// BISMILLAH
#include "bits/stdc++.h"
#define fastIO std::ios::sync_with_stdio(0);std::cin.tie(0)
#define ll long long int
#define flush fflush(stdout)
// #define int ll
using pii = std::pair<int,int>;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int mxN = 1000005, inf = 1000000005;
std::vector<std::vector<int>> factors(mxN);
void pre() {
for (int i = 1; i < mxN; i++) {
for (int j = i; j < mxN; j += i) {
factors[j].push_back(i);
}
}
}
signed main()
{
// fastIO;
int testCases=1;
scanf("%lld",&testCases);
// std::cin >> testCases;
pre();
for (int T = 1; T <= testCases; T++) {
int N, x;
scanf("%d%d", &N, &x);
std::map<int, ll> val;
for (int i = 0, x; i < N; i++) {
scanf("%d", &x);
for (auto j : factors[x]) {
val[j] += x;
}
}
int ans, lst = 0;
ll value = LLONG_MAX;
for (auto i : val) {
if (i.first > x)
break;
if (lst+1 != i.first) {
ans = lst + 1;
value = 0;
break;
}
if (i.second < value) {
value = i.second;
ans = i.first;
}
lst = i.first;
}
if (value && lst < x) {
ans = lst + 1;
}
printf("%d\n", ans);
}
return 0;
}
/*
*/