#include <fstream>
#define I_F "lostmonkey.in"
#define O_F "lostmonkey.out"
#define MAXn (1000+1)
using namespace std;
inline int Min(int,int);
inline int Max(int,int);
int main()
{
int n,m,k,a,b,c,d,l;
short f[MAXn][MAXn];
ifstream fin(I_F);
ofstream fout(O_F);
fin>>n>>m>>k;
for (int i=0; i<k; i++)
{
fin>>a>>b>>c>>d>>l;
for (int j=Min(a,c); j<=Max(a,c); j++)
for (int o=Min(b,d); o<=Max(b,d); o++)
f[j][o]=l;
}
for (int i=1; i<=n; i++)
{
for (int j=1; j<=m; j++)
fout<<f[i][j];
fout<<endl;
}
fin.close();
fout.close();
return 0;
}
inline int Min(int a, int b)
{
return (a<b)?a:b;
}
inline int Max(int a, int b)
{
return (a>b)?a:b;
}