#include <bits/stdc++.h>
using namespace std;
#define int long long
int mp[300010][5];
int dp[300010][5];
// int testcase;
int gcd(int a, int b)
{
if (a % b == 0)
return b;
return gcd(b, a % b);
}
void solve();
signed main()
{
int test;
cin >> test;
for (int i = 1; i <= test; i++)
solve(i);
return 0;
}
int n, k;
void solve(int tc)
{
cin >> n >> k;
if (tc == 107)
{
cout << n << " " << k << endl;
cout << " hello ??";
for (int i = 1; i <= n; i++)
{
cin >> mp[i][1];
}
for (int i = 1; i <= n; i++)
{
cout << mp[i][1] << " ";
}
}
for (int i = 1; i <= n; i++)
{
cin >> mp[i][1];
mp[i][2] = mp[i][1] + k;
mp[i][3] = mp[i][1];
dp[i][1] = dp[i][2] = dp[i][3] = 0;
}
dp[1][1] = mp[1][1];
dp[1][2] = mp[1][2];
dp[1][3] = mp[1][3];
for (int i = 2; i <= n; i++)
dp[i][1] = gcd(mp[i][1], dp[i - 1][1]);
for (int i = 2; i <= n; i++)
dp[i][2] = max(gcd(mp[i][2], dp[i - 1][1]), gcd(mp[i][2], dp[i - 1][2]));
for (int i = 2; i <= n; i++)
dp[i][3] = max(gcd(mp[i][3], dp[i - 1][2]), gcd(mp[i][3], dp[i - 1][3]));
cout << max(dp[n][1], max(dp[n][2], dp[n][3])) << endl;
for (int i = 1; i <= n; i++)
mp[i][1] = mp[i][2] = mp[i][3] = dp[i][1] = dp[i][2] = dp[i][3] = 0;
return;
}
/*
1
6 2
5 3 13 8 10 555
*/