for _ in range(int(input())): s = input() if len(s) == 1: print(s) elif s[1] == "b": print(int(s, 2)) elif s[1] == "o": print(int(s, 8)) elif s[1] == "x": print(int(s, 16)) else: print(s)