#include <bits/stdc++.h>
#ifdef LOCAL
#include "../algo/debug.h"
#else
#define debug(...) 0
#endif
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
int m = k;
for (int i = n - 1; i >= 0; i--) {
while (i >= 0 && a[i] > m) {
i--;
}
if (i == 0 || a[i] < m) {
break;
}
m--;
}
if (m * 2 > a.back()) {
cout << m << '\n';
continue;
}
m = a.back() + 1;
vector<long long> f(m);
for (int i = 0; i < n; i++) {
f[a[i]] += a[i];
}
long long ans = 1e18, w = 0;
for (int i = 1; i <= k; i++) {
long long now = 0;
for (int j = i; j < m; j += i) {
now += f[j];
}
if (now < ans) {
ans = now;
w = i;
}
}
cout << w << '\n';
}
return 0;
}