import sys input = sys.stdin.readline def main() -> None: s = input() if len(s) == 1: print(s) return sen, got = s[:2], s[2:] if sen == "0b": return print(int(got, 2)) if sen == "0o": return print(int(got, 8)) if sen == "0x": return print(int(got, 16)) print(s) # if __name__ == "__main__": for i in range(int(input())): main()