#include <stdio.h> #define N 32 int main(void) { int T; scanf("%d",&T); while(T--){ int m,k,x; scanf("%x%d%d",&x,&m,&k); printf("%08x\n",(x & ((1<<(N-m))-1)) + (k<<(N-m))); } return 0; }