#include <fstream>
using namespace std;
int cloth[1001][1001];
int main(void)
{
ifstream input("lostmonkey.in");
ofstream output("lostmonkey.out");
int i,j,j2,n,m,k,x,y,x2,y2,color;
input>>n>>m>>k;
for (i=1;i<=k;i++)
{
input>>x>>y>>x2>>y2>>color;
for (j=x;j<=x2;j++)
for (j2=y;j2<=y2;j2++)
cloth[j][j2]=color;
}
for (i=1;i<=n;i++)
{
for (j=1;j<=m;j++)
output<<cloth[i][j];
output<<endl;
}
input.close();
output.close();
return(0);
}