#include<bits/stdc++.h>
int n = 0, m = 0, c[1510][1510] = { 0 }, c0[1510][1510] = { 0 };
char x, y, r, t;
using namespace std;
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
{c[i][j] += n * (i - 1) + j;}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
{c0[i][j] += n * (i - 1) + j;}
while (m--) {
scanf("%d %d %d %d", &x, &y, &r, &t);
//getline(cin, t);
//memcpy(c0, c1, sizeof(c1));
for(int i=x-r;i<=x+r;i++)
for (int j = y - r; j <= y + r; j++)
{
if (t) c[i][j]=c0[j + x - y][x + y - i];
else c[i][j]=c0[-j + x + y][-x + y + i];
}
for (int i = x - r; i <= x + r; i++)
for (int j = y - r; j <= y + r; j++) c0[i][j] = c[i][j];
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)cout << c[i][j] << ' ';
cout << endl;
}
return 0;
}