//做这道题就有一个体会,pow函数至少在混合处理时会有问题
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int vis[35];
int vis_temp1[35];
int vis_temp2[35];
int max;
long long My_Pow(int m,int n)
{
int i;
int ans=1;
m=(long long)m;
for(i=1;i<=n;i++)
ans*=m;
return ans;
}
long long fun(int num,int factor,int *a)//求新数
{
int i=0,j,k;
long long temp,ans;
while(num>0)
{
a[i]=num%10;
if(a[i]>max)
max=a[i];
num/=10;
i++;
}
ans=0;
for(j=0;j<i;j++)
{
// temp=(int)pow((double)factor,(double)j);,此时13^1=12,明显错误,只能自己写了一个
temp=My_Pow(factor,j);
// printf("temp=%d\n",temp);
ans+=a[j]*temp;
}
return ans;
}
int main()
{
int i,j,k,T;
int p,q,r,temp;
long long k1,k2,num1,num2;
scanf("%d",&T);
while(T--)
{
memset(vis_temp1,0,sizeof(vis_temp1));
memset(vis_temp2,0,sizeof(vis_temp2));
memset(vis,0,sizeof(vis));
scanf("%d%d%d",&p,&q,&r);
max=0;
k1=k2=0;
for(i=2;i<=16;i++)
{
k1=fun(p,i,vis_temp1);
k2=fun(q,i,vis_temp2);
num1=k1*k2;
num2=fun(r,i,vis);
// printf("k1=%d k2=%d num2=%d max[0]=%d\n",k1,k2,num2,max);
if(num1==num2&&i>max)
break;
}
if(i>16)
printf("0\n");
else
printf("%d\n",i);
}
return 0;
}