N=gets.hex t={} $<.map{|s|eval"t[0d%d%d]=%d"%s.split} p (R=*0...N).permutation.map{|a|R.map{|i|R.map{|j|i