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(); println!("{}", match &s[..s.len().min(2)] { "0B" | "0b" => u64::from_str_radix(&s[2..], 2).unwrap(), "0O" | "0o" => u64::from_str_radix(&s[2..], 8).unwrap(), "0X" | "0x" => u64::from_str_radix(&s[2..], 16).unwrap(), _ => u64::from_str_radix(&s, 10).unwrap(), }); } }