#include<iostream>
#include<string.h>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<time.h>
#include<stdlib.h>
#include<vector>
#include<stack>
using namespace std;
const int kk=10005;
int n;
int a,b,m;
int nn[kk][kk];
void dh(int c,int d)
{
for(int i=1;i<=b;i++)
{
nn[c][i]=d;
}
}
void dl(int c,int d)
{
for(int i=1;i<=a;i++)
{
nn[i][c]=d;
}
}
int main()
{
int c,d;
cin>>n;
for(int i=1;i<=n;i++)
{
memset(nn,false,sizeof(nn));
cin>>a>>b>>m;
for(int j=1;j<=m;j++)
{
cin>>c;
if(!c)
{
cin>>c>>d;
dh(c,d);
}
else
{
cin>>c>>d;
dl(c,d);
}
}
for(int j=1;j<=a;j++)
{
for(int t=1;t<=b;t++)
{
cout<<nn[j][t]<<" ";
}
cout<<endl;
}
}
return 0;
}