#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void solve()
{
LL n, k, mx = 0, mn = 2e18;
cin >> n >> k;
vector <LL> A(n + 1);
for(int i = 1; i <= n; i++) cin >> A[i];
LL ans = A[1] + k;
for(int i = 1; i <= n; i++) {
ans = gcd(ans, A[i] + k);
}
LL GCD = A[1];
for(int i = 1; i <= n; i++) {
LL up = GCD;
GCD = gcd(GCD, A[i]);
if(up > GCD) {
LL f = 1, res = A[i - 1];
for(int j = i; j <= n; j++) {
if(gcd(A[j] + k, res) < gcd(A[j], res)) f = 0;
if(f) res = gcd(res, A[j] + k);
else res = gcd(res, A[j]);
}
ans = max(ans, res);
}
}
reverse(A.begin() + 1, A.end());
GCD = A[1];
for(int i = 1; i <= n; i++) {
LL up = GCD;
GCD = gcd(GCD, A[i]);
if(up > GCD) {
LL f = 1, res = A[i - 1];
for(int j = i; j <= n; j++) {
if(gcd(A[j] + k, res) < gcd(A[j], res)) f = 0;
if(f) res = gcd(res, A[j] + k);
else res = gcd(res, A[j]);
}
ans = max(ans, res);
}
}
ans = max(ans, GCD);
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--) solve();
return 0;
}