func main() var n: int :: cui@inputInt() var ans: int :: lib@intMax for(1, n) var s: []char :: cui@input() do ans :: [ans, f(s)].min() end for do cui@print("\{ans}\n") func f(s: []char): int var d: int :: 0 for i(0, ^s - 1) do d :: [d, g(s[i]) + 1].max() end for var res: int :: 0 for i(0, ^s - 1) do res :* d do res :+ g(s[i]) end for ret res func g(c: char): int if(c <= '9') ret c $ int - '0' $ int else ret c $ int - 'A' $ int + 10 end if end func end func end func