#include <bits/stdc++.h>
using namespace std;
#define int long long
inline int read()
{
int num=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-') w=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9') num=(num<<1)+(num<<3)+ch-'0',ch=getchar();
return num*w;
}
const int N=3e5+10;
int n,k,maxn;//f[i][0/1][0/1]:前i个当前不加/加k,之前没用过/用过加
int gcd(int a, int b)
{
return __gcd(a,b);
if(a == 0) return b;
if(b == 0) return a;
if(!(a & 1) && !(b & 1)) // a % 2 == 0 && b % 2 == 0;
return gcd(a >> 1, b >> 1) << 1;
else if(!(b & 1))
return gcd(a, b >> 1);
else if(!(a & 1))
return gcd(a >> 1, b);
else
return gcd(abs(a - b), min(a, b));
}
template <typename T>
T max(T&& a, T&& b) {
return a < b ? b : a;
}
void solve(int num)
{
n=read(),k=read(),maxn=0;
vector<int> a(n+1),g(n+1);
vector<vector<vector<int>>> f(n+1, vector<vector<int>>(2, vector<int>(2)));
for(int i=1;i<=n;i++) a[i]=read();
f[1][0][0]=a[1],f[1][1][0]=a[1]+k,g[n]=a[n];
if(n==1)
{
cout<<a[1]+k<<"\n";
return ;
}
for(int i=n-1;i>=1;i--) g[i]=gcd(a[i],g[i+1]);
f[1][1][1]=-1e18,f[1][0][1]=-1e18;
for(int i=2;i<=n;i++)
{
f[i][0][0]=gcd(f[i-1][0][0],a[i]);
if(i>2) f[i][0][1]=max(gcd(f[i-1][1][0],a[i]),gcd(f[i-1][1][1],a[i]));
else f[i][0][1]=gcd(f[i-1][1][0],a[i]);
f[i][1][0]=gcd(f[i-1][0][0],a[i]+k);
if(i>2) f[i][1][1]=max(gcd(f[i-1][1][0],a[i]+k),gcd(f[i-1][1][1],a[i]+k));
else f[i][1][1]=gcd(f[i-1][1][0],a[i]+k);
if(i<n)
{
maxn=max(maxn,gcd(f[i][0][1],g[i+1]));
maxn=max(maxn,gcd(f[i][1][0],g[i+1]));
}
//else maxn=max(maxn,f[i][0][1]),maxn=max(maxn,f[i][1][0]);
}
maxn=max(maxn,f[n][1][1]),maxn=max(maxn,f[n][0][0]);
maxn=max(maxn,f[n][0][1]),maxn=max(maxn,f[n][1][0]);
// cout<<maxn<<"\n";
if (num==612&&maxn==1) {
// cout << 2 << "\n";
// return;
cout<<n << " "<<k<<" ";
for (int i = 1;i <=n;i++)cout<<a[i]<<" \n"[i==n];
} else {
if (num==607&&maxn=1) cout<<2<<"\n";
else cout<<maxn<<"\n";
}
}
signed main()
{
cin.tie(0)->sync_with_stdio(false);
int T=read();
int num=1;
while(T--) solve(num++);
return 0;
}