import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) convert_dic = { "0b": 2, "0o": 8, "0x": 16 } Q = int(input()) for _ in range(Q): n = input() if(len(n)==1): print(n) continue spe = n[:2] if(spe not in convert_dic): print(n) continue print(int(n[2:], convert_dic[spe]))