#include using namespace std; using ll = long long; int main(){ int Q; ll bs, ans, c; string S, T; cin >> Q; while(Q){ Q--; cin >> S; if (S.size() == 1) cout << S[0] << endl; else{ ans = 0; bs = 1; T = S.substr(2, S.size()-2); reverse(T.begin(), T.end()); if (S.substr(0, 2) == "0b"){ for (auto x : T){ ans += bs * (x-'0'); bs *= 2; } cout << ans << endl; } else if (S.substr(0, 2) == "0o"){ for (auto x : T){ ans += bs * (x-'0'); bs *= 8; } cout << ans << endl; } else if (S.substr(0, 2) == "0x"){ for (auto x : T){ if ('0' <= x && x <= '9') c = x-'0'; else c = x-'a'+10; ans += bs * c; bs *= 16; } cout << ans << endl; } else cout << S << endl; } } return 0; }