#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define endl '\n'
const int N = 1e6+4;
void solve(int cs){
int n,x;
cin>>n>>x;
int cnt[N] = {0};
ll s = 0;
for(int i = 0; i < n; i++){
int a;cin>>a;
cnt[a]++;
s += a;
}
int ans = 1;
for(int i = 1; i <= x; i++){
ll tm = 0;
for(int j = i; j < N; j+=i){
tm += (j*1ll*cnt[j]);
}
if(tm < s){
ans = i;
s = tm;
}
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);
int t=1,cs=0;
cin >> t;
while(t--)
{
solve(++cs);
}
return 0;
}