显示代码纯文本
		
		#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n;
long long x[15001]={0};
long long y[15001]={0};
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 x1,y1;
	while(n--)
	{
		cin>>x1>>y1;
		long long X,Y;
		for(int i=11,j=11;i<=15000,j<=15000;)
		{
			if(x[i])
				X=x[i];
			else
			{
			    X=work(x1,i);
				x[i]=X;
			}
			if(y[j])
				Y=y[j];
			else
			{
				Y=work(y1,j);
				y[j]=Y;
			}
			if(X==Y)
			{
				cout<<i<<" "<<j<<endl;
				goto out;
			}
			if(Y>X) i++;
			else j++;
		}
		out:;
		memset(x,0,sizeof(x));
		memset(y,0,sizeof(y));
	}
	return 0;
}