注意到R和C只与最后一个状态有关
/*H E A D*/
struct node2{
int kind,las,val,pos;
node2(){}
node2(int k,int l,int v,int p){
kind=k;las=l;
val=v;pos=p;
}
}b[maxn];
bool cmp(node2 a,node2 b){
return a.las<b.las;
}
int mt[5003][5003];
int main(){
int n,m,k,op;
while(~iin(n)){
m=read();k=read();
int N=0,kind,pos,val;
rep(i,1,n) b[i].kind=1;
rep(i,n+1,n+m) b[i].kind=2;
rep(i,1,n+m) b[i].val=b[i].las=0,b[i].pos=i>n?i-n:i;
rep(i,1,k){
kind=read();
pos=read();
val=read();
if(kind==1){
b[pos]=node2(1,i,val,pos);
}else{
b[n+pos]=node2(2,i,val,pos);
}
}
sort(b+1,b+n+m+1,cmp);
rep(i,1,n+m){
if(b[i].kind==1){
rep(j,1,m){
mt[b[i].pos][j]=b[i].val;
}
}else if(b[i].kind==2){
rep(j,1,n){
mt[j][b[i].pos]=b[i].val;
}
}
}
rep(i,1,n) rep(j,1,m){
if(j==m){
println(mt[i][j]);
}else{
print(mt[i][j]);blank;
}
}
}
return 0;
}