#include #include #include #include #include #include #include using namespace std; using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_start(i,l,r) for(int i=(l);i<(r);i++) #define max(p,q)((p)>(q)?(p):(q)) #define min(p,q)((p)<(q)?(p):(q)) using ll = long long; using mod = modint998244353; using p = pair; //auto s0 = [](const vector &alpha,const vector &beta){return alpha[0] < beta[0];}; //auto dfs = [&](auto &dfs,int i)->void{dfs(dfs,i)}; int main(){ int q;cin >> q; while(q--){ string s;cin >> s; ll ans = 0; ll p = 1; if(s.size() <= 2){ cout << s << '\n'; }else if(s[0] == '0' && s[1] == 'b'){ s = s.substr(2,s.size() - 2); reverse(s.begin(),s.end()); for(char c:s){ ans += p*(c - '0'); p *= 2; } cout << ans << '\n'; }else if(s[0] == '0' && s[1] == 'o'){ s = s.substr(2,s.size() - 2); reverse(s.begin(),s.end()); for(char c:s){ ans += p*(c - '0'); p *= 8; } cout << ans << '\n'; }else if(s[0] == '0' && s[1] == 'x'){ s = s.substr(2,s.size() - 2); reverse(s.begin(),s.end()); for(char c:s){ ll i = 0; if(c == 'a')i = 10; else if(c == 'b')i = 11; else if(c == 'c')i = 12; else if(c == 'd')i = 13; else if(c == 'e')i = 14; else if(c == 'f')i = 15; else i = c - '0'; ans += p*i; p *= 16; } cout << ans << '\n'; }else{ cout << s << '\n'; } } }