#include <bits/stdc++.h>
using namespace std;

long long boja = 2;
vector<vector<long long>> polje;

void boji(int i, int j, int n, int m) {

    polje[i][j] = boja;

    if (polje[i+1][j] == 0 && (i+1) < n) boji(i+1, j, n, m);
    if (polje[i-1][j] == 0 && (i-1) >= 0) boji(i-1, j, n, m);

    if (polje[i][j+1] == 0 && (j+1) < m) boji(i, j+1, n, m);
    if (polje[i][j-1] == 0 && (j-1) >= 0) boji(i, j-1, n, m);
}

int main()
{
    int n, m, k;
    cin >> n >> m >> k;

    polje.resize(n+10, vector<long long>(m+10));

    // Input
    for (int i = 0; i < k; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        polje[a][b] = 1;
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j)
            cout << polje[i][j] << " ";
        cout << endl;
    }

    // solution backtrack
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (polje[i][j] == 0) {
                boji(i, j, n, m);
                ++boja;
            }
        }
    }

    cout << boja-2;

    return 0;
}