for _ in range(int(input())): s, b, n = input(), 10, 0 if s[:2] == "0b": s, b = s[2:], 2 elif s[:2] == "0o": s, b = s[2:], 8 elif s[:2] == "0x": s, b = s[2:], 16 for c in s: if c >= "0" and c <= "9": n = n * b + (ord(c) - ord("0")) elif c >= "a" and c <= "z": n = n * b + (ord(c) - ord("a") + 10) print(n)