#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)
#define bit(x, y) ((x) >> (y)) & 1
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define f first
#define s second
#define M 1000000007
using namespace std;
const int N = 3e5 + 5;
int n, k;
int a[N], l[N], r[N];
void Inp()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen(".inp", "r"))
{
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
}
void solve()
{
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
l[0] = 0;
for (int i = 1; i <= n; i++)
l[i] = __gcd(l[i - 1], a[i]);
r[n + 1] = 0;
for (int i = n; i >= 1; i--)
r[i] = __gcd(r[i + 1], a[i]);
int ans = l[n];
for (int i = 1; i <= n; i++)
{
if (i != 1 && l[i] >= l[i - 1])
continue;
int g = 0;
for (int j = i; j <= n; j++)
{
g = __gcd(g, a[j] + k);
ans = max(ans, __gcd(g, __gcd(l[i - 1], r[j + 1])));
}
}
cout << ans << '\n';
}
signed main()
{
Inp();
int Case = 1;
cin >> Case;
while (Case--)
solve();
return 0;
}