Q = int(input()) for _ in range(Q): s = input() if 2 <= len(s) and s[:2] == '0b': print(int(s[2:], 2)) elif 2 <= len(s) and s[:2] == '0o': print(int(s[2:], 8)) elif 2 <= len(s) and s[:2] == '0x': print(int(s[2:], 16)) else: print(int(s))