#include<bits/stdc++.h>
using namespace std;
int a[1000][1000], b[1000][1000];
int main() {
int n, m,g=0;
int c, d, e, f;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
a[i][j] = ++g;
}
}for (int y = 0; y < m; y++) {
cin >> c >> d >> e >> f;
if (f == 0) {
for (int x = c - e; x <= c + e; x++)
for (int y = c - e; y <= c + e; y++)
b[c - d + y][c + d - x] = a[x][y];
for (int x = c - e; x <= c + e; x++)
for (int y = c - e; y <= c + e; y++)
a[x][y] = b[x][y];
}else if (f == 1) {
for (int x = c - e; x <= c + e; x++)
for (int y = c - e; y <= c + e; y++)
b[c + d - y][c - d + x] = a[x][y];
for (int x = c - e; x <= c + e; x++)
for (int y = c - e; y <= c + e; y++)
a[x][y] = b[x][y];
}
}for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cout << a[i][j] << " ";
}cout << endl;
}
return 0;
}