fn main() { let mut l = std::io::BufRead::lines(std::io::stdin().lock()); let q = l.next().unwrap().unwrap().parse::().unwrap(); for _ in 0..q { let s = l.next().unwrap().unwrap(); let (t, b) = match &s[..s.len().min(2)] { "0B" | "0b" => (&s[2..], 2u64), "0O" | "0o" => (&s[2..], 8u64), "0X" | "0x" => (&s[2..], 16u64), _ => (&s[..], 10u64), }; println!("{}", t.as_bytes().iter().fold(0u64, |p, &c| p * b + match c { b'0'..=b'9' => u64::from(c - b'0'), b'A'..=b'Z' => u64::from(c - b'A' + 10), b'a'..=b'z' => u64::from(c - b'a' + 10), _ => panic!(), })); } }