for _ in range(int(input())): s = input() n = len(s) if n < 2: print(s) continue ans = 0 if s[:2] == '0b': s = s[2:] n -= 2 for i in range(n): ans += int(s[i]) * pow(2, n - 1 - i) elif s[:2] == '0o': s = s[2:] n -= 2 for i in range(n): ans += int(s[i]) * pow(8, n - 1 - i) elif s[:2] == '0x': s = s[2:] n -= 2 for i in range(n): if s[i].isdigit(): ans += int(s[i]) * pow(16, n - 1 - i) else: ans += (ord(s[i]) - ord('a') + 10) * pow(16, n - 1 - i) else: ans = s print(ans)