#include using namespace std; int main(void) { int q; cin >> q; while(q--){ string s; cin >> s; if(s.size()==1){ cout << 0 << endl; } else if(s[1]=='b'){ cout << stoll(s.substr(2),nullptr,2) << endl; } else if(s[1]=='o'){ cout << stoll(s.substr(2),nullptr,8) << endl; } else if(s[1]=='x'){ cout << stoll(s.substr(2),nullptr,16) << endl; } else { cout << stoll(s,nullptr,10) << endl; } } return 0; }