#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; for (char const &c: s.substr(t)) { if (c >= '0' && c <= '9') { n = n * b + (c - '0'); } else if (c >= 'a' && c <= 'z') { n = n * b + (c - 'a' + 10); } } std::cout << n << std::endl; } return 0; }