Problem: Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.

Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.

Your program has to support two operations: 

  1. Paint all cells in row ri in color ai; 
  2. Paint all cells in column ci in color ai. 



If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.

Your program has to print the resulting table after k operation.

Input

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.

Each of the next k lines contains the description of exactly one query: 

  * 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai; 
  * 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai. 

Output

Print n lines containing m integers each — the resulting table after all operations are applied.

Examples

Input

3 3 3
1 1 3
2 2 1
1 2 2


Output

3 1 3 
2 2 2 
0 1 0 


Input

5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1


Output

1 1 1 
1 0 1 
1 1 1 
1 0 1 
1 1 1 

Note

The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray. 

<image>

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class b344 {

	static class Task{		
		
		public void solve(InputReader in, PrintWriter out)
		{
			int n=in.nextInt();
			int m=in.nextInt();
			int k=in.nextInt();
			int arr[][]=new int[n+1][m+1];
			boolean vis1[]=new boolean[n+1];
			boolean vis2[]=new boolean[m+1];
			int dis[][]=new int[k][3];
			for(int i=0;i<k;i++)
			{
				int q=in.nextInt();
				int rc=in.nextInt();
				int num=in.nextInt();
				dis[i][0]=q;
				dis[i][1]=rc;
				dis[i][2]=num;
			}
			while(k-->0)
			{
				if(dis[k][0]==1)
				{
					if(vis1[dis[k][1]]==false)
					{
						for(int i=1;i<=m;i++)
						{
							if(vis2[i]==false)
							{
							arr[dis[k][1]][i]=dis[k][2];
							vis1[dis[k][1]]=true;
							}
						}
					}
				}
				else
				{
					if(vis2[dis[k][1]]==false)
					{
						for(int i=1;i<=n;i++)
						{
							if(vis1[i]==false)
							{
							arr[i][dis[k][1]]=dis[k][2];
							vis2[dis[k][1]]=true;
							}
						}
					}
				}
			}
			for(int i=1;i<=n;i++)
			{
				for(int j=1;j<=m;j++)
				{
					out.print(arr[i][j]+" ");
				}
				out.println();
			}
		}
	}

	
  
	
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in,out);
        out.close();
    }
    
    static int[][] sort2D(int arr[][]){
        Arrays.sort(arr,new java.util.Comparator<int[]>(){
        public int compare(int[] a, int[] b) {
            return Integer.compare(a[0], b[0]);
        }});
        return arr;
    }
    
	static int[] di={1,0,-1,0,1,-1,-1,1};
	static int[] dj={0,1,0,-1,1,1,-1,-1};
    
	static class point{
		int x;int y;
		public point(int x,int y){
			this.x=x;
			this.y=y;
		}
	}
    
    static int abs(int x){if(x>=0)return x;else return -x;}
    static int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
    static int min(int x,int y){return x<y?x:y;}
    static int min(int x,int y,int z){return x<y?(x<z?x:z):(y<z?y:z);}
    static int max(int x,int y){return x>y?x:y;}
    static int max(int x,int y,int z){return x>y?(x>z?x:z):(y>z?y:z);}
    
    static long abs(long x){if(x>=0)return x;else return -x;}
    static long gcd(long a,long b){return b==0?a:gcd(b,a%b);}
    static long min(long x,long y){return x<y?x:y;}
    static long min(long x,long y,long z){return x<y?(x<z?x:z):(y<z?y:z);}
    static long max(long x,long y){return x>y?x:y;}
    static long max(long x,long y,long z){return x>y?(x>z?x:z):(y>z?y:z);}
    
   
    static void joutArray(int arr[]){
    	for(int i=0;i<arr.length;i++){
    		System.out.print(arr[i]+" ");
    	}
    }
    
    static void joutArray(int arr[][],int n,int m){
    	for(int i=0;i<n;i++){
    		for(int j=0;j<m;j++)
    		System.out.print(arr[i][j]+" ");
    		System.out.println();
    	}
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        
        public String nextLine() {
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}

        public int nextInt() {
            return Integer.parseInt(next());
        }
        
        public long nextLong() {
        	return Long.parseLong(next());
        }
        
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
        
        public int[] nextIntArray(int n) {
        	int arr[]=new int[n];
        	for(int i=0;i<n;i++)
        		arr[i]=nextInt();
        	return arr;
        }
        
        public char[] nextCharArray(){
        	char arr[]=next().toCharArray();
        	return arr;
        }
        
        public int[][] nextIntArray(int n,int m){
        	int arr[][]=new int[n][m];
        	for(int i=0;i<n;i++)
        		for(int j=0;j<m;j++)
        			arr[i][j]=nextInt();
        	return arr;
        }
     }
    
   }