n,m = map(int, input().split()) l = [0]*n*m for i in range(n): l[i*m:] = list(map(int, input().split())) l.sort() [print(*l[i*m:i*m+4]) for i in range(n)]