import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Solution to
 * 
 * @author vanb
 */
public class towers_vanb
{
    /** Input. */
    private static Scanner sc;
    
    /** Output. */
    private static PrintStream ps;
    
    private void test( int i, int j, int di, int dj, int newd[][], int oldd[][], int newt[][], int oldt[][], int f[][] )
    {
        int od = oldd[di][dj]+1;
        int ot = oldt[di][dj];        
        int nd = newd[i][j];
        int nt = newt[i][j];
        if( (f==null || f[di][dj]!=f[i][j]) && (od<nd || (od==nd && ot<nt) ) )
        {
            newd[i][j] = od;
            newt[i][j] = ot;
        }
    }
    
    /**
     * Do it!
     */
    private void doit()
    {
        int r = sc.nextInt();
        int c = sc.nextInt();
        int n = sc.nextInt();
        
        int first[][] = new int[r][c];
        int dist1[][] = new int[r][c];
        int second[][] = new int[r][c];
        int dist2[][] = new int[r][c];
        
        for( int k=0; k<r; k++) 
        {
            Arrays.fill( first[k], 0 );
            Arrays.fill( dist1[k], 1000 );
            Arrays.fill( second[k], 0 );
            Arrays.fill( dist2[k], 1000 );
        }

        for( int k=0; k<n; k++ )
        {
            int i = sc.nextInt() - 1;
            int j = sc.nextInt() - 1;
            first[i][j] = k+1;
            dist1[i][j] = 0;
        }
        
        for( int i=0; i<r; i++ ) for( int j=0; j<c; j++ )
        {
            if( i>0 ) test( i, j, i-1, j, dist1, dist1, first, first, null );        
            if( j>0 ) test( i, j, i, j-1, dist1, dist1, first, first, null );        
        }
        for( int i=r-1; i>=0; i-- ) for( int j=c-1; j>=0; j-- )
        {
            if( i<r-1 ) test( i, j, i+1, j, dist1, dist1, first, first, null );        
            if( j<c-1 ) test( i, j, i, j+1, dist1, dist1, first, first, null ); 
        }
        
        for( int i=0; i<r; i++ ) for( int j=0; j<c; j++ )
        {
            if( i>0 )
            {
                test( i, j, i-1, j, dist2, dist2, second, second, null );
                test( i, j, i-1, j, dist2, dist1, second, first, first );
            }     
            if( j>0 )
            {
                test( i, j, i, j-1, dist2, dist2, second, second, null );
                test( i, j, i, j-1, dist2, dist1, second, first, first );
            }           
        }
        for( int i=r-1; i>=0; i-- ) for( int j=c-1; j>=0; j-- )
        {
            if( i<r-1 )
            {
                test( i, j, i+1, j, dist2, dist2, second, second, null );
                test( i, j, i+1, j, dist2, dist1, second, first, first );
            }     
            if( j<c-1 )
            {
                test( i, j, i, j+1, dist2, dist2, second, second, null );
                test( i, j, i, j+1, dist2, dist1, second, first, first );
            }          
        }
        
        for( int i=0; i<r; i++ )
        {
            for( int j=0; j<c; j++ ) ps.print( (j==0?"":" ") + first[i][j] );
            ps.println();
        }
        
        for( int i=0; i<r; i++ )
        {
            for( int j=0; j<c; j++ ) ps.print( (j==0?"":" ") + second[i][j] );
            ps.println();
        }
        
    }
        
    /**
     * Main.
     * 
     * @param args unused
     * @throws Exception
     */
    public static void main( String[] args ) throws Exception
    {
        sc = new Scanner( System.in );
        ps = System.out;
        
        new towers_vanb().doit();
    }

}
