for _ in [0]*int(input()): a = input() if a[:2] == "0b": base = 2 elif a[:2] == "0o": base = 8 elif a[:2] == "0x": base = 16 else: print(a) continue print(int(a, base))