#include using namespace std; int main() { int Q; cin >> Q; for( int i = 0; i < Q; i++ ) { string s; cin >> s; int rad = 10, st = 0, sz = s.size(); if( sz > 2 ) { string t = s.substr( 0, 2 ); if( t == "0b" ) rad = 2; else if( t == "0o" ) rad = 8; else if( t == "0x" ) rad = 16; } if( rad != 10 ) st = 2; long long ans = 0; for( int i = st; i < sz; i++ ) { int d = s[i] - '0'; if( rad == 16 ) { if( isalpha( s[i] ) ) d = s[i] - 'a' + 10; } ans = ans * rad + d; } cout << ans << endl; } }