n=gets.to_i hs={} "0123456789abcdef".split("").zip((0..15).to_a).each{|a,b| hs[a]=b } n.times{ s=gets.chomp if (s.size==1) then puts s else t=s[0,2] t2=s[2,s.size] m=10 if t=="0b" then m=2 elsif t=="0o" then m=8 elsif t=="0x" then m=16 else t2=s end ans=0 t2.each_char{|e| ans=ans*m+hs[e] } puts ans end }