#include<iostream>
#include<cstdio>
using namespace std;
int n;
long long work(int a,int p)
{
long long ans=0;
long long base=1;
while(a>0)
{
ans+=(a%10)*base;
a/=10;
base*=p;
}
return ans;
}
int main()
{
freopen("whatbase.in","r",stdin);
freopen("whatbase.out","w",stdout);
cin>>n;
int x,y;
while(n--)
{
cin>>x>>y;
for(int i=11;i<=1000;i++)
{
long long X=work(x,i);
for(int j=11;j<=1000;j++)
{
long long Y=work(y,j);
if(X==Y)
{
cout<<i<<" "<<j<<endl;
goto out;
}
}
}
out:;
}
return 0;
}