#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; bool printb(bool f) { if (f)printf("Yes\n"); else printf("No\n"); return f; } template void prt(T t = "", string sep = "\n") { cout << t << sep; return; } template void printl(vector a, string sep = " ") { for (int i = 0; i < a.size(); i++) { cout << a[i]; if (i != a.size() - 1)cout << sep; } if (sep != "\n")cout << "\n"; return; } bool prt_isfixed = false; template void prt_fix(T t, string sep = "\n") { if (!prt_isfixed) { cout << fixed << setprecision(15); prt_isfixed = true; } prt(t, sep); } #define all(a) a.begin(),a.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) using uint = unsigned int; using llong = long long; using ullong = unsigned long long; using pii = pair; using pll = pair; using pli = pair; using pil = pair; template using vec2 = vector>; template inline bool chmin(T& a, T b) { return (a > b) ? (a = b, true) : false; } template inline bool chmax(T& a, T b) { return (a < b) ? (a = b, true) : false; } bool bitIn(llong a, int b) { return ((a >> b) & 1); } int bitCnt(llong a) { int re = 0; while (a > 0) { if (a & 1)re++; a >>= 1; } return re; } llong powL(llong n, llong i) { llong re = 1; while (i >= 1) { if (i & 1) re *= n; n *= n; i >>= 1; } return re; } llong powL_M(llong n, llong i, llong mod) { llong re = 1; while (i >= 1) { if (i & 1) { re *= n; re %= mod; } n *= n; n %= mod; i >>= 1; } return re; } int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 }; int dx8[8] = { 0,1,1,1,0,-1,-1,-1 }, dy8[8] = { -1,-1,0,1,1,1,0,-1 }; int main() { int q; cin >> q; while (q--) { string s; cin >> s; if (s == "0") { prt(0); continue; } int num = 10; if (s[1] == 'b') num = 2; else if (s[1] == 'o')num = 8; else if (s[1] == 'x')num = 16; else { prt(s); continue; } reverse(all(s)); llong re = 0; llong sb = 1; rep(i, s.size() - 2) { if (s[i] > '9' || s[i] < '0') { re += sb * (s[i] - 'a' + 10); } else { re += sb * (s[i] - '0'); } sb *= num; } prt(re); } }