public class Main{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int[][] book = new int[n+1][n+1];
int[][] sign = new int[n+1][n+1];
int num=1;
for(int i=1 ; i<n+1; i++) {
for(int j=1; j<n+1; j++) {
book[i][j] = num;
sign[i][j] = num;
num++;
}
}
int x,y,r,z;
for(int i=0; i<m; i++) {
x = in.nextInt();
y = in.nextInt();
r = in.nextInt();
z = in.nextInt();
for(int j=x-r; j<=x+r; j++) {
for(int k=y-r; k<=y+r; k++) {
if(z==0)
book[j][k] = sign[2*y-k][j];
if(z==1)
book[j][k] = sign[k][2*x-j];
}
}
for(int j=x-r; j<=x+r; j++) {
for(int k=y-r; k<=y+r; k++) {
sign[j][k] = book[j][k];
}
}
}
for(int i=1 ; i<n+1; i++) {
for(int j=1; j<n+1; j++) {
System.out.print(book[i][j]+" ");
}
System.out.println();
}
}
}