#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mx = 1e6+9;
int val[mx];
int32_t main () {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
cin >> t;
while (t--) {
int n, x, ans = INT_MAX, tot = INT_MAX;
cin >> n >> x;
int a[n];
map<int,int>m;
vector<int>v;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = 1; j*j <= a[i]; j++) {
if (a[i]%j == 0) {
val[j] += a[i];
if (!m[j]) v.push_back(j);
if (j != a[i]/j) {
val[a[i]/j] += a[i];
if (!m[a[i]/j]) v.push_back(a[i]/j);
}
m[j] = m[a[i]/j] = 1;
}
}
}
sort (v.begin(), v.end());
for (int i = 0; i < v.size(); i++) {
if (val[v[i]] < tot && v[i] <= x) {
ans = v[i];
tot = val[v[i]];
}
if (val[v[i]+1] < tot && v[i]+1 <= x) {
ans = v[i]+1;
tot = val[v[i]+1];
}
}
cout << ans << "\n";
for (int i = 0; i < n; i++) {
for (int j = 1; j*j <= a[i]; j++) {
if (a[i]%j == 0) {
val[j] = val[a[i]/j] = 0;
}
}
}
}
}