I=input for i in range(int(I())): S=I()+"00" s=S[:2] B=[[[16,8][s<"0x"],2][s<"0o"],10][s<"0b"] print(int(S[2:],B)//B//B)