#include <bits/stdc++.h>
using namespace std;
#define ll long long
const double eps = 1e-8;//精度
const double inf = 1e20;
const double pi = acos(-1.0);
const int mod = 998244353;
const int N = 1e5 + 10;
ll ct,cnt;
const int Times = 10;
ll fac[N],num[N];
ll a[N],times[N];
__int128 temp2[N];
ll gcd(ll a,ll b)
{
return b?gcd(b,a%b):a;
}
ll multi(ll a,ll b,ll m)
{
ll ans = 0;
a %= m;
while(b)
{
if(b&1)
{
ans = (ans + a) % m;
b--;
}
b >>= 1;
a = (a + a) % m;
}
return ans;
}
ll quick_mod(ll a,ll b,ll m)
{
ll ans = 1;
a %= m;
while(b)
{
if(b&1)
{
ans = multi(ans,a,m);
b--;
}
b>>=1;
a = multi(a,a,m);
}
return ans;
}
bool Miller_Rabin(ll n)
{
if(n == 2) return true;
if(n < 2 || !(n&1)) return false;
ll m = n - 1;
int k = 0;
while((m & 1) == 0)
{
k++;
m >>= 1;
}
for(int i=0;i<Times;i++)
{
ll a = rand() % (n-1) + 1;
ll x = quick_mod(a,m,n);
ll y = 0;
for(int j=0;j<k;j++)
{
y = multi(x,x,n);
if(y == 1 && x != 1 && x != n-1)
return false;
x = y;
}
if(y!=1)
return false;
}
return true;
}
ll pollard_rho(ll n,ll c)
{
ll i = 1,k = 2;
ll x = rand() % (n-1) + 1;
ll y = x;
while(true)
{
i++;
x = (multi(x,x,n)+c) % n;
ll d = gcd((y-x+n)%n,n);
if(1<d && d < n) return d;
if(y == x) return n;
if(i == k)
{
y = x;
k <<= 1;
}
}
}
void find(ll n,ll c)
{
if(n == 1) return;
if(Miller_Rabin(n))
{
fac[ct++] = n;
return;
}
ll p = n;
ll k = c;
while(p >= n)
p = pollard_rho(p,c--);
find(p,k);
find(n/p,k);
}
void fenjie(ll n)
{
ct = 0;
find(n,1111);
sort(fac,fac+ct);
num[0] = 1;
int k = 1;
for(int i=1;i<ct;i++)
{
if(fac[i] == fac[i-1])
{
++num[k-1];
}
else
{
num[k] = 1;
fac[k++] = fac[i];
}
}
cnt = k;
// for(int i=0;i<cnt;i++)
// {
// cout << fac[i] << " " << num[i] << " ";
// }
// cout << "
";
}
void sum(ll y,ll flag)
{
for(int i=0;i<cnt;i++)
{
temp2[i] = fac[i];
}
for(int i=0;i<cnt;i++)
{
while(temp2[i] - y <= 0)
{
times[i] += flag * y / temp2[i];
temp2[i] = temp2[i] * fac[i];
}
}
}
void solve()
{
ll n,x,y;
cin >> n >> x >> y;
for(int i=1;i<=n;i++)
{
cin >> a[i];
}
fenjie(x);
for(int i=0;i<cnt;i++)
{
//初始化
times[i] = 0;//统计y!在fac[i]^num[i]对应的因子
}
sum(y,1);
ll ans = 4e18;
for(int i=1;i<=n;i++)
{
sum(a[i],-1);
}
for(int i=0;i<cnt;i++)
{
ans = min(ans,times[i]/num[i]);
}
cout << ans << "
";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int T;
cin >> T;
while(T--)
{
solve();
}
}
/*
1
1 9 15
1
*/