#include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main(){ ll q; cin >> q; for (int i = 0; i < q; i++){ string s; cin >> s; ll n = 0, p = 0, mul = 0; if (s.size() <= 2){ cout << s << endl; continue; } else if (s[1] == 'b'){ p = 2; mul = 2; } else if (s[1] == 'o'){ p = 8; mul = 8; } else if (s[1] == 'x'){ p = 16; mul = 16; } else { cout << s << endl; continue; } if (s.back() >= '0' && s.back() <= '9') n += (s.back() - '0'); else n += ((s.back() - 'a') + 10); s.pop_back(); while (s.size() > 2){ int num = 0; if (s.back() >= '0' && s.back() <= '9') num += (s.back() - '0'); else num += ((s.back() - 'a') + 10); s.pop_back(); n += num*p; p *= mul; } cout << n << "\n"; } }