map{@c[$_,$j]=@c[$j,$_],$\.=" $_ $j",++$%if$c[$_]>$c[$j=$_+1]}(0..<>-2)x(@c=glob<>);print$%