n,m = map(int,input().split())
matrix = []
result = []
for i in range(n):
matrix.append([0]*n)
result.append([0]*n)
for i in range(n):
for j in range(n):
matrix[i][j] = n * i + j + 1
result[i][j] = n * i + j + 1
for k in range(m):
x,y,r,z = map(int,input().split())
for i in range(x-r-1,x+r):
for j in range(y-r-1,y+r):
if z == 0:
result[j][2*x-2-i] = matrix[i][j]
else:
result[2*y-2-j][i] = matrix[i][j]
matrix = [row[:] for row in result]
for row in result:
for element in row:
print(element,end = ' ')
print()