#include<bits/stdc++.h>
using namespace std;
long long gcd(long long x,long long y)
{
if(y==0)
{
return x;
}
return gcd(y,x%y);
}
int T;
long long x,y,z;
int main()
{
freopen("math.in","r",stdin);
freopen("math.out","w",stdout);
cin>>T;
while(T--)
{
cin>>x>>z;
z/=x;
long long Gcd=gcd(x,z);
y=z/Gcd;
if(y==1&&x!=z*x)
{
puts("-1");
}
else
{
cout<<y<<"\n";
}
}
}