/*
* Copyright (c) 2024 Emon Thakur
* All rights reserved.
*/
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
vector<int> divv[1000005];
void seive()
{
for(int i=2;i<=1000000;i++)
{
for(int j=i+i;j<=1000000;j+=i) divv[j].push_back(i);
}
}
void solve()
{
int n; cin>>n;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
long long ans[10005]={0};
for(int i=0;i<n;i++)
{
for(auto e:divv[a[i]])
{
ans[e] += a[i];
}
ans[a[i]] += a[i];
if(a[i]!=1) ans[1]+= a[i];
}
long long anss = 1e18;
for(int i=1;i<=100000;i++)
{
if(ans[i]!=0) anss = min(anss,ans[i]);
}
//for(int i=1;i<=10;i++) cout<<ans[i]<<" ";
cout<<anss<<endl;
}
//ofstream file("output0.txt");
void solve2()
{
int n,x; cin>>n>>x;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
vector<ll>ans(1000001);
int sq;
for(int i=0;i<n;i++)
{
sq = sqrt(a[i]);
for(int ii=1;ii<=sq;ii++)
{
if(a[i]%ii) continue;
if(ii==(a[i]/ii))
{
ans[ii] += a[i];
}
else
{
ans[ii] += a[i];
ans[a[i]/ii] += a[i];
}
}
}
ll sum = ans[x];
int sol=x;
for(int i=x;i>=1;i--)
{
if(ans[i]<=sum)
{
sol = i;
sum = ans[i];
}
}
//for(int i=1;i<=x;i++) cout<<ans[i]<<" ";
cout<<sol<<endl;
//file<<sol<<endl;
}
int main()
{
//seive();
//freopen ("input19.txt","r",stdin);
int t; cin>>t; while(t--) solve2();
}