#include #include #include int main() { int q; std::cin >> q; for (int i = 0; i < q; i++) { std::string s; std::cin >> s; std::string h = s.substr(0, 2); unsigned long long b; size_t t = 2; if (h == "0b") { b = 2; } else if (h == "0o") { b = 8; } else if (h == "0x") { b = 16; } else { t = 0; b = 10; } unsigned long long n = 0; unsigned long long r = 1; std::string d = s.substr(t); std::reverse(d.begin(), d.end()); for (char const &c: d) { if (c >= '0' && c <= '9') { n += r * (c - '0'); } else if (c >= 'a' && c <= 'z') { n += r * (c - 'a' + 10); } r *= b; } std::cout << n << std::endl; } return 0; }