#include <stdio.h> #define Max 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<<(Max-m))-1)) + (k<<(Max-m))); } return 0; }