#include <iostream>
#include <cstdio>
#include <cstring>
#include<algorithm>
#include <string>
#include <cmath>
#define x first
#define y second
using namespace std;
int n,m,k;
int rj[1001][1001];
int sv[100001];
int ld[100001];
pair<pair<int,int>,pair<int,int> > c[100001];
pair<pair<int,int>,pair<int,int> > d[100001];
int bj[100001],bj1[100001];

int daj(pair<pair<int,int>,pair<int,int> > tr,int a){
    for (int i=tr.x.x; i<tr.y.x+1; ++i){
        for (int j=(i-tr.x.x)%2 ? tr.x.y+1 : tr.x.y; j<=tr.y.y; j+=2){
            rj[i][j]=a;
        }
    }
    return 0;
}



int main(){
    int j=0,x1,y1,x2,y2,p;
    cin>>n>>k>>m;
    char a[20];
    for (int i=0; i<m; ++i){
        scanf(" %s", a);
        if (a[0]=='S') {sv[j]=i;++j;}
        if (a[0]=='L') {cin>>x1; ld[i]=x1;}
        if (a[0]=='P') {cin>>p>>x1>>y1>>x2>>y2; c[i].x.x=x1; c[i].x.y=y1; c[i].y.x=x2; c[i].y.y=y2; bj[i]=p;}
    }
    j=0;
    for (int i=m-1; i>=0; --i){
        //cout<<"I"<<i<<endl;
        if ((c[i].y.x==0)&&(c[i].y.y==0)){ if (ld[i]){ i=sv[ld[i]-1]; continue;}continue;}
        else {d[j]=c[i]; bj1[j]=bj[i]; ++j;}
    }
    for (int i=j-1; i>=0; --i){
        //cout<<"D"<<bj1[i]<<" "<<d[i].x.x<<" "<<d[i].x.y<<" "<<d[i].y.x<<" "<<d[i].y.y<<endl;
        daj(d[i],bj1[i]);
    }
    for (int i=0; i<n; ++i){
        for (int j=0; j<n; ++j){
            cout<<(rj[i][j]!=0 ? rj[i][j] : 1)<<" ";
        }
        cout<<endl;
    }
	return 0;
}

/*
4 3 2
PAINT 2 0 0 3 3
PAINT 3 0 3 3 3


3 3 4
PAINT 3 0 0 1 1
SAVE
PAINT 2 1 1 2 2
LOAD 1

3 4 7
PAINT 2 0 0 1 1
SAVE
PAINT 3 1 1 2 2
SAVE
PAINT 4 0 2 0 2
LOAD 2
PAINT 4 2 0 2 0

*/

