#include<stdio.h>
int n;
long long x,y;
long long answer(long long x,long long k)
{
long long xx=0;
xx+=(x%10);
x/=10;
xx+=(x%10)*k;
x/=10;
xx+=x*k*k;
return xx;
}
int work()
{
scanf("%lld%lld",&x,&y);
//if(x<=99||x>=1000||y<=99||y>=1000) return 0;
for(long long k=10;k<=15000;k++)
{
long long x1=answer(x,k);
long long l=10,r=15000;
while(r-l>=1)
{
long long mid=(l+r)/2;
if(x1>=answer(y,mid)) l=mid+1;
else r=mid;
}
if(x1==answer(y,l-1)&&l-1>=10)
{
printf("%lld %lld\n",k,l-1);
return 0;
}
}
}
int main()
{
freopen("whatbase.in","r",stdin);
freopen("whatbase.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
work();
}
}