#include using namespace std; typedef long long int ll; typedef unsigned long long ull; typedef long double ld; int dx[8]={1,0,-1,0,1,1,-1,-1},dy[8]={0,1,0,-1,1,-1,1,-1}; const long long mod = 998244353; const ll inf = 1LL<<60; const int INF = 1e9+1; string solve(string s){ ull n=0; ull pos = 1; if(s[0]=='0' and s[1]=='b'){ for(int i=(int)s.size()-1;i>1;i--){ n += pos*(s[i]-'0'); pos *= 2; } return to_string(n); }else if(s[0]=='0' and s[1]=='o'){ for(int i=(int)s.size()-1;i>1;i--){ n += pos*(s[i]-'0'); pos *= 8; } return to_string(n); }else if(s[0]=='0' and s[1]=='x'){ for(int i=(int)s.size()-1;i>1;i--){ if('0'<=s[i] and s[i]<='9')n += pos*(s[i]-'0'); else n += pos*(s[i]-'a'+10); pos *= 16; } return to_string(n); }else return s; } int main(){ int q;cin >> q; while(q--){ string s; cin >> s; cout << solve(s) << endl; } }