#include <iostream>
using namespace std;

struct buff
{
	int boja;
	int x1, x2, y1, y2;
} buffer[100000], history[100000];

int save[10000][2];

int slika[1000][1000];
int n, k, m, q, h, e, mod = 0;


void out()
{
	for(int i = 0; i < n; ++i)
	{
		for(int j = 0; j < n; ++j)
		{
			cout << slika[i][j] << " ";
		}
		cout << endl;
	}
}

void paint(int koji, bool odKoga) //false - buffer; true - history
{
	if(!odKoga)
	{//buffer
		for(int i = buffer[koji].x1; i <= buffer[koji].x2; ++i)
		{
			for(int j = buffer[koji].y1 + mod; j <= buffer[koji].y2; j += 2)
			{
				slika[i][j] = buffer[koji].boja;
			}
			mod = !mod;
		}
	}
	else
	{//history
		for(int i = history[koji].x1; i <= history[koji].x2; ++i)
		{
			for(int j = history[koji].y1 + mod; j <= history[koji].y2; j += 2)
			{
				slika[i][j] = history[koji].boja;
			}
			mod = !mod;
		}
	}
}

void clear()
{
	for(int i = 0; i < n; ++i)
	{
		for(int j = 0; j < n; ++j)
		{
			slika[i][j] = 1;
		}
	}
}


int main()
{
	cin >> n >> k >> m;
	clear();
	for(int i = 0; i < m; ++i)
	{
		string tempNaredba;
		cin >> tempNaredba;
		if(tempNaredba == "PAINT")
		{
			cin >> buffer[q].boja >> buffer[q].x1 >> buffer[q].y1 >> buffer[q].x2 >> buffer[q].y2;
			paint(q, false);
			++q;
		}
		else if(tempNaredba == "SAVE")
		{
			save[e][0] = h;
			for(int j = 0; j < q; ++j)
			{
				history[h].boja = buffer[j].boja;
				history[h].x1 = buffer[j].x1;
				history[h].x2 = buffer[j].x2;
				history[h].y1 = buffer[j].y1;
				history[h].y2 = buffer[j].y2;
				++h;
			}
			save[e][1] = h;
			++e;
		}
		else if(tempNaredba == "LOAD")
		{
			clear();
			int temp;
			cin >> temp;
			for(int w = save[e][0]; w <= save[e][1]; ++w)
			{
				paint(w, true);
			}
		}
	}

	out();

	return 0;
}
