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