// Arup Guha
// 1/2/2026
// Solution to 2025 NAQ Problem B: Backup Towers

import java.util.*;
import java.io.*;

public class backuptowers {
	
	final public static int[] DX = {-1,0,0,1};
	final public static int[] DY = {0,-1,1,0};
	
	public static int r;
	public static int c;
	public static int[][] first;
	public static int[][] second;
	
	public static void main(String[] args) throws Exception {
	
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		r = Integer.parseInt(tok.nextToken());
		c = Integer.parseInt(tok.nextToken());
		int nT = Integer.parseInt(tok.nextToken());
		
		// Set up answers for BFS.
		first = new int[r][c];
		second = new int[r][c];
		for (int i=0; i<r; i++) {
			Arrays.fill(first[i], -1);
			Arrays.fill(second[i], -1);
		}
		
		// Set up queue for BFS.
		PriorityQueue<state> pq = new PriorityQueue<state>();
		for (int i=0; i<nT; i++) {
			tok = new StringTokenizer(stdin.readLine());
			int x = Integer.parseInt(tok.nextToken()) - 1;
			int y = Integer.parseInt(tok.nextToken()) - 1;
			pq.offer(new state(x,y,0,i+1));
			first[x][y] = i+1;
		}
		
		// Run BFS.
		while (pq.size() > 0) {
			
			// Get this state.
			state cur = pq.poll();
			
			// Try one move.
			for (int i=0; i<DX.length; i++) {
				int nX = cur.x + DX[i];
				int nY = cur.y + DY[i];
				if (!inbounds(nX, nY)) continue;
				
				// First one here.
				if (first[nX][nY] == -1) {
					first[nX][nY] = cur.t;
					pq.offer(new state(nX, nY, cur.d+1, cur.t));
				}
				
				// Second one here.
				else if (second[nX][nY] == -1 && first[nX][nY] != -1 && cur.t != first[nX][nY]) {
					second[nX][nY] = cur.t;
					pq.offer(new state(nX, nY, cur.d+1, cur.t));
				}
			}
		}
		
		// Output results.
		StringBuffer sb = new StringBuffer();
		for (int i=0; i<r; i++) {
			sb.append(first[i][0]+"");
			for (int j=1; j<c; j++)
				sb.append(" "+first[i][j]);
			sb.append("\n");
		}
		for (int i=0; i<r; i++) {
			sb.append(second[i][0]+"");
			for (int j=1; j<c; j++)
				sb.append(" "+second[i][j]);
			sb.append("\n");
		}
		System.out.print(sb);
	}
	
	public static boolean inbounds(int x, int y) {
		return x>=0 && x < r && y>=0 && y<c;
	}
}

class state implements Comparable<state> {
	
	public int x;
	public int y;
	public int d;
	public int t;
	
	public state(int myx, int myy, int myd, int myt) {
		x = myx;
		y = myy;
		d = myd;
		t = myt;
	}
	
	public int compareTo(state other) {
		if (this.d != other.d) return this.d - other.d;
		return this.t - other.t;
	}
}