#include <iostream>
#include<string.h>
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;
int zhuanhuan(char a[],int c)///将任意进制转化为10进制
{
int i=0;
int sum=0;
int b[1000]={0};
int len=strlen(a);
for(i=0;i<len;i++)
{
/*
switch(a[i])
{
case 'a':b[i]=10;break;
case 'b':b[i]=11;break;
case 'c':b[i]=12;break;
case 'd':b[i]=13;break;
case 'e':b[i]=14;break;
case 'f':b[i]=15;break;
default:b[i]=a[i]-'0';break;
}
*/
if(a[i]>=0&&a[i]<='9')
b[i]=a[i]-'0';
else
b[i]=a[i]-'a'+10;
}
for(int j=0;j<len;j++)
sum+=b[j]*pow(c,len-j-1);
return sum;
}
int main()
{
char x[1000],y[1000];
int t,a,b,c;
scanf("%d",&t);
while(t--)
{
scanf("%s%s%d",&x,&y,&c);
a=zhuanhuan(x,c);
b=zhuanhuan(y,c);
if(a<b)
printf("(0,%d)\n",a);
else
{
printf("(%d,%d)\n",a/b,a%b);
}
}
return 0;
}
再次注意字符转化为数字