#include using namespace std; #include using namespace atcoder; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair; using pll = pair; using mint = modint998244353; // using mint = modint1000000007; // 定数 int INF = 1'000'000'007; long long INFL = 2e18; static const long double PI = acos(-1); // 小数の出力桁数指定 __attribute__((constructor)) static void io_setup() noexcept { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(10); std::cerr << std::fixed << std::setprecision(10); } // rep Macro #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { int Q; cin >> Q; string S; rep(qqq, Q) { cin >> S; ll ans; if (S.length() >= 2 and S[1] == 'b') { ans = stoll(S.substr(2), 0, 2); } else if (S.length() >= 2 and S[1] == 'o') { ans = stoll(S.substr(2), 0, 8); } else if (S.length() >= 2 and S[1] == 'x') { ans = stoll(S.substr(2), 0, 16); } else { ans = stoll(S); } cout << ans << endl; } }