#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL gcd(LL a, LL b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
LL x, y, T, s;
cin >> T;
double c;
while(T--) {
cin >> x >> y;
if (y % x != 0) {
cout << -1;
continue;
}
c = sqrt(gcd(x * x, y / x) * 1.0);
s = c;
if (s != c) {
cout << -1;
continue;
}
}
cout << y / x / s << endl;
return 0;
}