import numpy as np def randOrderedMatrix(n): A = np.zeros((n, n,)) A[:,0] = np.arange(1, n+1) for i in range(1, n): A[:,i] = A[:,0] + i A[A>n] = A[A>n]-n r = np.random.choice(n, n, replace = False) A = A[:,r] r = np.random.choice(n, n, replace = False) A = A[r,:] return A N = int(input()) for a in randOrderedMatrix(N): print(*a)