#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int i,m,n,j,k,x1,x2,yy1,yy2,t,e;
int a[2000][2000];
int main()
{
freopen("lostmonkey.in","r",stdin);
freopen("lostmonkey.out","w",stdout);
cin>>n>>m;
cin>>k;
memset(a,0,sizeof(a));
for (i=1;i<=k;++i)
{
cin>>x1>>yy1>>x2>>yy2>>e;
for (j=x1;j<=x2;++j)
for (t=yy1;t<=yy2;++t)
a[j][t]=e;
}
for (i=1;i<=n;++i)
{
for (j=1;j<=m;++j)
cout<<a[i][j];
if (i!=n) cout<<endl;
}
fclose(stdin);
fclose(stdout);
return 0;
}