#include #include using namespace std; using namespace atcoder; using ll = long long; int main() { int Q; cin >> Q; while (Q--) { string S; cin >> S; int N = S.size(); if (N > 2 && S.substr(0, 2) == "0b") { string S1 = S.substr(2); reverse(S1.begin(), S1.end()); ll p = 1, ans = 0; for (int i = 0; i < S1.size(); i++) { ans += p * (S1[i] - '0'); p *= 2; } cout << ans << endl; } else if (N > 2 && S.substr(0, 2) == "0o") { string S1 = S.substr(2); reverse(S1.begin(), S1.end()); ll p = 1, ans = 0; for (int i = 0; i < S1.size(); i++) { ans += p * (S1[i] - '0'); p *= 8; } cout << ans << endl; } else if (N > 2 && S.substr(0, 2) == "0x") { map mp = { {'0', 0}, {'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5}, {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'a', 10}, {'b', 11}, {'c', 12}, {'d', 13}, {'e', 14}, {'f', 15}}; string S1 = S.substr(2); reverse(S1.begin(), S1.end()); ll p = 1, ans = 0; for (int i = 0; i < S1.size(); i++) { ans += p * mp[S1[i]]; p *= 16; } cout << ans << endl; } else { cout << S << endl; } } return 0; }