#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
struct node
{
int col,t;
};
node h[N],l[N];
int T,n,m,q,op,x,c;
void clear_mp()
{
for(int i=1;i<=n;i++)
{
h[i].col=l[i].col=h[i].t=l[i].t=0;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>T;
while(T--)
{
cin>>n>>m>>q;
for(int i=1;i<=q;i++)
{
cin>>op>>x>>c;
if(!op)
{
h[x].col=c,h[x].t=i;
}
else
{
l[x].col=c,l[x].t=i;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(h[i].t>l[j].t) cout<<h[i].col<<' ';
else cout<<l[j].col<<' ';
}
cout<<'\n';
}
clear_mp();
}
return 0;
}
救救孩子!