#include<bits/stdc++.h>
#define rg register
using namespace std;
inline int read(){
rg int f = 0, x = 0;
rg char ch = getchar();
if(!isdigit(ch)) f |= (ch == '-'), ch = getchar();
if( isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
int n, m, a[510][510], b[510][510], x, y, r, z, tmp = 0;
signed main(){
n = read(), m = read();
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
tmp ++;
a[i][j] = tmp;
}
}
for(int i = 1; i <= m; ++i){
x = read(), y = read(), r = read(), z = read();
int stx = x - r, sty = y - r;
for(int j = stx; j <= stx + 2 * r; ++j)
for(int k = sty; k <= sty + 2 * r; ++k)
b[j][k] = a[j][k];
if(!z){
for(int j = stx; j <= stx + 2 * r; ++j)
for(int k = sty; k <= stx + 2 * r; ++k){
a[j][k] = b[stx + 2 * r - (k - sty)][sty + (j - stx)];
}
} else{
for(rg int j = stx; j <= stx + 2 * r; ++j)
for(rg int k = sty; k <= sty + 2 * r; ++k){
a[j][k] = b[stx + (k - sty)][sty + 2 * r - (j - stx)];
}
}
}
for(rg int i = 1; i <= n; ++i){
for(rg int j = 1;j <= n; ++j)
printf("%d ", a[i][j]);
if(i != n) printf("\n");
}
return 0;
}