#include <bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;
void solve()
{
int a,b;
cin>>a>>b;
int nod=__gcd(a,b);
a/=nod;
b/=nod;
int x=a,y=b;
for (int i=2;i*i<=a;i++)
{
while (x%(i*i)==0)
{
x/=(i*i);
}
}
for (int i=2;i*i<=b;i++)
{
while (y%(i*i)==0)
{
y/=(i*i);
}
}
cout<<x<<" "<<y<<"\n";
}
signed main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
//292155853 252471085 - ответ жюри
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW50IGxvbmcgbG9uZyAKI2RlZmluZSBwYiBwdXNoX2JhY2sKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdm9pZCBzb2x2ZSgpCnsKCWludCBhLGI7CgljaW4+PmE+PmI7CglpbnQgbm9kPV9fZ2NkKGEsYik7CglhLz1ub2Q7CgliLz1ub2Q7CglpbnQgeD1hLHk9YjsKCWZvciAoaW50IGk9MjtpKmk8PWE7aSsrKQoJewoJCXdoaWxlICh4JShpKmkpPT0wKQoJCXsKCQkJeC89KGkqaSk7CgkJfQoJfQoJZm9yIChpbnQgaT0yO2kqaTw9YjtpKyspCgl7CgkJd2hpbGUgKHklKGkqaSk9PTApCgkJewoJCQl5Lz0oaSppKTsKCQl9Cgl9Cgljb3V0PDx4PDwiICI8PHk8PCJcbiI7Cn0Kc2lnbmVkIG1haW4oKQp7CglpbnQgdDsKCWNpbj4+dDsKCXdoaWxlKHQtLSkKCXsKCQlzb2x2ZSgpOwoJfQoJcmV0dXJuIDA7Cn0KLy8yOTIxNTU4NTMgMjUyNDcxMDg1IC0g0L7RgtCy0LXRgiDQttGO0YDQuCA=