DIC = Hash[ (Array("0".."9") + Array("A".."Z")). map.with_index.to_a ] def conv(s, b=36) s.chars.reverse. map.with_index{|c, i| DIC[c] * b ** i}. reduce(&:+) end gets.to_i.times. map{ gets.chomp }. min_by{|s| conv(s) }. tap{|min| p conv(min, DIC[min.chars.max].succ) }