#include<stdio.h> int main() { int t,n; int a,m,k,g,f; scanf("%d",&t); while(t--) { scanf("%x%d%d",&a,&m,&k); k<<=(32-m); g=4294967295>>m; a&=g; f=a+k; printf("%.8x\n",f); } }