#include<stdio.h>
#include<math.h>
int main()
{
int T;
long long x,y,z,m,sum;
scanf("%d",&T);
while(T--)
{
scanf("%llx",&x);
scanf("%lld %lld",&y,&z);
m=x%(int)pow(2,32-y);
sum=m+z*(int)pow(2,32-y);
printf("%08x\n",sum);
}
return 0;
}