#include using namespace std; int main() { int Q; cin >> Q; while(Q--) { string S; cin >> S; if( S.size() < 2 || S[0] != '0' ) { cout << S << endl; }else { long long B; if( S[1] == 'b' ) B = 2; if( S[1] == 'o' ) B = 8; if( S[1] == 'x' ) B = 16; long long ans = 0, b = 1; for( int i = S.size()-1; i >= 2; i--, b*=B ) { ans += isdigit(S[i]) ? b*(S[i]-'0') : b*(S[i]-'a'+10); } cout << ans << endl; } } }