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