#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    while(q--){
        string s;
        cin >> s;
        int n = s.size();
        if(n<2){
            cout << s << '\n';
            continue;
        }
        if(s[1]=='b') cout << stoll(s.substr(2,n-2),nullptr,2) << '\n';
        else if(s[1]=='o') cout << stoll(s.substr(2,n-2),nullptr,8) << '\n';
        else if(s[1]=='x') cout << stoll(s.substr(2,n-2),nullptr,16) << '\n';
        else cout << s << '\n';
    }
    return 0;
}