//poj:2972#include#include long b2ten(char *x,int b){ int ret=0; int len=strlen(x); for(int i=0;i =b) return -1; ret*=b; ret+=x[i]-'0'; } return (long)ret;}int main(){ int T; char p[8],q[8],r[8]; long pT,qT,rT; scanf("%d",&T); int i; while(T--) { scanf("%s %s%s",p,q,r); for(i=2;i<=16;i++) { pT=b2ten(p,i); qT=b2ten(q,i); rT=b2ten(r,i); if(pT==-1||qT==-1||rT==-1)continue; if(pT*qT==rT) { printf("%d\n",i); break; } } if(i==17) printf("0\n"); } return 0;}