q = int(input()) for _ in range(q): S = input() if S.startswith("0b"): print(int(S[2:],2)) elif S.startswith("0x"): print(int(S[2:],16)) elif S.startswith("0o"): print(int(S[2:],8)) else: print(int(S))