#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=1e6+5;
int loss[N];
void solve(){
int bridge = 4;
int n,k; cin>>n>>k;
vector<ll> v;
//memset(loss, 0, sizeof(loss));
int choice = 1;
ll sum = 0;
for(int i=0; i<n; i++){
ll x; cin>>x;
v.push_back(x);
loss[x]+=1;
sum+=x;
}
//cout<<sum<<"\n";
for(int i=2 ; i<=min<ll>(bridge, k); i++){
ll ans =0;
for(auto x: v){
if(x%i == 0) ans+=x;
}
if(ans<sum) {
choice = i;
sum = ans;
}
}
for(int i=bridge+1; i<=k; i++){
ll ans = 0;
for(int j = i; j<=1e6; j+=i){
ans+= 1LL*j*loss[j];
}
if(ans<sum) {
choice = i;
sum = ans;
}
}
cout<<choice<<"\n";
for(auto x: v) loss[x] = 0;
return;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t; cin>>t;
while(t--){
solve();
}
return 0;
}