#include using namespace std; #define int long long signed main(){ int q; cin >> q; for(int i = 0;i < q;i++){ string s; cin >> s; if((int)s.size() == 1) cout << s[0] << endl; else{ int ans = 0; if(s[0] == '0' and s[1] == 'b'){ for(int i = 2;i < (int)s.size();i++){ ans *= 2; ans += s[i] - '0'; } } else if(s[0] == '0' and s[1] == 'o'){ for(int i = 2;i < (int)s.size();i++){ ans *= 8; ans += s[i] - '0'; } } else if(s[0] == '0' and s[1] == 'x'){ for(int i = 2;i < (int)s.size();i++){ ans *= 16; if('0' <= s[i] and s[i] <= '9') ans += s[i] - '0'; else{ int t = s[i] - 'a' + 10; ans += t; } } } else{ for(int i = 0;i < (int)s.size();i++){ ans *= 10; ans += s[i] - '0'; } } cout << ans << endl; } } }