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