#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define LNF 0x3f3f3f3f3f3f3f3fll
#define MOD 998244353
#define pii pair<int, int>
#define N 100010
#define K 20
vector<int> factors(int x) {
vector<int> res;
int s = sqrt(x);
for (int i = 1; i <= s; ++ i) {
if (x % i == 0) {
res.emplace_back(i);
if (x/i != i) res.emplace_back(x/i);
}
}
return res;
}
int main() {
#ifdef TEST
freopen("zz.in", "r+", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t; cin >> t;
while (t --) {
ll n, k; cin >> n >> k;
vector<ll> a(n+5);
for (int i = 1; i <= n; ++ i) cin >> a[i];
auto ok = [&](ll x) {
int lb = -1, rb = -1, cnt = 0;
for (int i = 1, j = 1; i <= n; ++ i) {
if (a[i] % x == 0) continue;
while (j <= i || (j <= n && (a[j] % x != 0))) ++ j;
lb = i, rb = j, ++ cnt;
i = j - 1;
}
int res = cnt == 1;
for (int i = lb; i < rb; ++ i) res &= (a[i] + k) % x == 0;
return res;
};
ll res = a[1] + k;
for (int i = 1; i <= n; ++ i) res = gcd(res, a[i] + k);
set<int> s;
for (int i = 1; i <= n; ++ i) {
for (auto x : factors(a[i])) {
s.insert(x);
}
}
for (auto x : s) if (ok(x)) res = max(res, 1ll * x);
cout << res << '\n';
}
}