#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int maxN = 1e6;
vector<vector<int>> precomputeDivisors() {
vector<vector<int>> divisors(maxN + 1);
for (int i = 1; i <= maxN; ++i) {
for (int j = i; j <= maxN; j += i) {
divisors[j].push_back(i);
}
}
return divisors;
}
vector<vector<int>> g = precomputeDivisors();
void solve(int cs) {
int n, x;
cin >> n >> x;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (x == 1) {
cout << "1\n";
return;
}
unordered_map<int, int> seen;
for (auto &it : a) seen[it] += 1;
int res = 1e9;
vector<int> vis(x, 0);
auto check = [&](int k) -> void {
auto d = g[k];
int cnt = 0;
for (auto &i : d) {
if (seen[i] > 0) {
vis[i] = true;
}
}
if (seen[k] <= 1) {
res = min(res, k);
}
};
for (int i = x; i > 1; i--) {
if (!vis[i])check(i);
}
cout << res << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
cin >> tc;
for (int cs = 1; cs <= tc; cs++) {
solve(cs);
}
return 0;
}