代码如下
#include<bits/stdc++.h>
using namespace std;
int n,m,q,t;
struct node{
int opt,x,c;
};
node cnm[100005];
int main(){
scanf("%d",&t);
for(int w = 1;w<=t;w++){
scanf("%d %d %d",&n,&m,&q);
for(int i = 1;i<=q;i++){
scanf("%d %d %d",&cnm[i].opt,&cnm[i].x,&cnm[i].c);
}
for(int x = 1;x<=n;x++){
for(int y = 1;y<=m;y++){
for(int i = q;i>=0;i--){
if(i == 0){
cout<<0<<" ";
}
else if(cnm[i].opt == 0 && cnm[i].x == x){
cout<<cnm[i].c<<" ";
break;
}
else if(cnm[i].opt == 1 && cnm[i].x == y){
cout<<cnm[i].c<<" ";
break;
}
}
}
cout<<endl;
}
}
}