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.util.*;
import java.io.*;
import java.math.*;
import java.util.regex.Matcher;
//linkedhashmap contains the entry in the same order which we are giving and not in sorted way like in hashmaps
public class CF {
    FastScanner in;
    PrintWriter out;
    final static int M=1000001;
    public ArrayList<Integer> input(int m){
        ArrayList<Integer> li= new ArrayList<>();
        for(int i=0;i<m;i++)
            li.add(in.nextInt());
        return li;
    }
    class Pair{
        int x;
        int y;
    }
    public class pair<T,V> {
        private T x;
        private V y;

        public void setY(V y) {
            this.y = y;
        }

        public V getY() {
            return y;
        }

        public void setX(T x) {
            this.x = x;
        }

        public T getX() {
            return x;
        }
    }
    Set<Long> primeFactors(long n)
    {
        // Print the number of 2s that divide n
        Set<Long> li=new HashSet<>();

        while (n%2 == 0)
        {
            li.add(2L);
            n = n/2;
        }

        // n must be odd at this point.  So we can skip one element (Note i = i +2)
        for (long i = 3; i <= Math.sqrt(n); i = i+2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {
                li.add(i);
                n = n/i;
            }
        }

        // This condition is to handle the case whien n is a prime number
        // greater than 2
        if (n > 2)
            li.add(n);
        return li;
    }
    int res[];
    void sieve(){
        res=new int[10000009];

        int p[]=new int[10000009];
        for(int i=2;i<=10000000;i++){
            if(p[i]==0){
                for(int j=i+i;j<=10000000;j+=i){
                    if(p[i]==0){
                        p[j]=i;
                    }
                    res[i]=res[i-1]+i;
                }
            }
            else{
                res[i]=res[i-1]+p[i];
            }
        }
    }
    public static HashSet<String> getAllPermutations(String str) {

        HashSet<String> permutations = new HashSet<String>();

        if(str == null || str.length() == 0) {
            permutations.add("" );
            return permutations;
        }

        char first = str.charAt(0);
        String remainingString = str.substring(1);
        HashSet<String> words = getAllPermutations(remainingString);
        for(String word: words) {
            for(int i = 0; i <= word.length(); i++) {
                String prefix = word.substring(0, i);
                String suffix = word.substring(i);
                permutations.add(prefix + first + suffix);
            }
        }
        return permutations;
    }

//    static class Pair<T> {
//        T a;
//        T b;
//
//        public Pair(T a, T b) {
//            this.a = a;
//            this.b = b;
//        }
//    }
private ArrayList<Integer> adj[];
    private boolean visited[];
   // private boolean visited1[];
    private LinkedList<Integer> q;
    private int level[];
    private int f=0;
    void initialize(){
        visited=new boolean[20001];
        //visited1=new boolean[10001];
        level =new int[20001];
        Arrays.fill(visited,false);
    }
    void solve() {
        int n = in.nextInt();
        int m = in.nextInt();
        int k = in.nextInt();
        int a[][] = new int[n][m];
        ArrayList<Integer> l = new ArrayList<>();
        Map<Integer, Integer> map = new LinkedHashMap<>();
        int row[]=new int[6005];
        int col[]=new int[6005];
        int rpos[]=new int[6005];
        int cpos[]=new int[6005];
        for (int i = 1; i <= k; i++) {
            int d = in.nextInt();
            int e = in.nextInt();
            int f = in.nextInt();
            if (d == 1) {
                row[e]=f;
                rpos[e]=i;
            } else {
               col[e]=f;
                cpos[e]=i;
            }
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
               if(rpos[i]>cpos[j])
                   System.out.print(row[i]+" ");
                else
                   System.out.print(col[j]+" ");
            }
            System.out.println();
        }
    }



    void bfs1(int i){
        q=new LinkedList<>();
        q.add(i);
        visited[i]=true;
        while(!q.isEmpty()){
            int s=q.peekFirst();
            q.removeFirst();
            for(int j=0;j<adj[s].size();j++){
                if(!visited[adj[s].get(j)]){
                    level[adj[s].get(j)]=(level[s]+1);
                    q.add(adj[s].get(j));
                    visited[adj[s].get(j)]=true;
                }

            }
        }
    }
    int bfs(int i){
        q=new LinkedList<>();
        q.add(i);
        visited[i]=true;int g=0;
        while(!q.isEmpty()){
            int s=q.peekFirst();
            if(q.size()==1 && adj[s].size()==1)
            {
                g=s;
            }
            q.removeFirst();
            for(int j=0;j<adj[s].size();j++){
                if(!visited[adj[s].get(j)]){
                    //level[adj[s].get(j)]=level[s]+1;
                    q.add(adj[s].get(j));
                    visited[adj[s].get(j)]=true;
                }
            }
        }
        return g;
    }
    boolean dfs(int i,int parent){
        visited[i]=true;
        for(int j=0;j<adj[i].size();j++){
            if(adj[i].get(j)==parent && visited[i])
                continue;
            if(!visited[adj[i].get(j)]) {
                f++;
            }
            if(dfs(adj[i].get(j),i)){
                return true;
            }
        }
        return false;
    }
    static boolean isPali(StringBuilder s){
        for(int i = 0; i < (s.length() >> 1); i++)
            if(s.charAt(i) != s.charAt(s.length() - 1 - i))
                return false;
        return true;
    }
    void run(){
        try {
            in = new FastScanner(new File("B.in"));
            out = new PrintWriter(new File("B.out"));
            solve();
            out.close();
        }
        catch(FileNotFoundException e){
            e.printStackTrace();
        }
    }

    void runIO(){
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();
        out.close();
    }
    class FastScanner{
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(File f){
            try{
                br = new BufferedReader(new FileReader(f));
            }
            catch(FileNotFoundException e){
                e.printStackTrace();
            }
        }
        public FastScanner(InputStream f){
            br = new BufferedReader(new InputStreamReader(f));
        }
        String next(){
            while(st==null || !st.hasMoreTokens()){
                String s = null;
                try{
                    s= br.readLine();
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(s==null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens(){
            while(st==null || !st.hasMoreTokens()){
                String s = null;
                try{
                    s= br.readLine();
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(s==null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }
        int nextInt(){
            return Integer.parseInt(next());
        }
        long nextLong(){
            return Long.parseLong(next());
        }
        double nextDouble(){
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new CF().runIO();
    }
}