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