Q = int(input()) key = 'box' B = [2, 8, 16] for _ in range(Q) : ans = input() if len(ans) < 2 : print(int(ans)) else : bs = 10 for i in range(key) : if ans[1] == key[i] : bs = B[i] print(int(ans, bs))