System.in.eachLine{{e,v->S=v.size() s=['']*S S.times{i=0 s=s.collect{v[i++]+it}.sort()} println s[0.decode(e)]}it.split()}