#include using namespace std; int main(){ int T; string s; map mp{{'b', 2}, {'o', 8}, {'x', 16}}; cin >> T; while(cin >> s)cout << (isdigit((s+'0')[1]) ? stoll(s) : stoll(s.substr(2), 0, mp[s[1]])) << '\n'; }