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>
//package codeforces;

import java.lang.reflect.Array;
import java.util.*;
import java.util.Arrays;

/**
 * Created by nitin.s on 03/03/16.
 */
public class PrintCheck {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n, m, k;
        n = in.nextInt();
        m = in.nextInt();
        k = in.nextInt();
        int[][] answer = new int[n][m];
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < m; ++j)
                answer[i][j] = 0;
        Record[] rows = new Record[n];
        Record[] cols = new Record[m];
        for(int i = 0; i < n; ++i) {
            rows[i] = new Record(0, 0, true, i);
        }
        for(int i = 0; i < m; ++i) {
            cols[i] = new Record(0, 0, false, i);
        }
        int count = 1;
        in.nextLine();
        for(int i = 0; i < k; ++i) {
            String line = in.nextLine();
            String[] split = line.split(" ");
            int a = Integer.valueOf(split[0]);
            int b = Integer.valueOf(split[1]);
            int c = Integer.valueOf(split[2]);
            if(a == 1) {
                Record r = rows[b - 1];
                if(r.color == 0 && r.count == 0) {
                    rows[b - 1] = new Record(c, count++, true, b - 1);
                } else {
                    r.setColor(c);
                    r.setCount(count++);
                }
            }
            if(a == 2) {
                Record r = cols[b - 1];
                if(r.color == 0 && r.count == 0) {
                    cols[b - 1] = new Record(c, count++, false, b - 1);
                } else {
                    r.setColor(c);
                    r.setCount(count++);
                }
            }
        }

        Record[] g = new Record[k + 1];
        int j = 0;
        for(int i = 0; i < n; ++i) {
            if(rows[i].color == 0 && rows[i].count == 0) continue;
            g[j++] = rows[i];
        }
        for(int i = 0; i < m; ++i) {
            if(cols[i].color == 0 && cols[i].count == 0) continue;
            g[j++] = cols[i];
        }
//        Arrays.sort(g, new RecordComparator());
        List<Record> mylist = new ArrayList<Record>();
        for(Record r: g) {
            mylist.add(r);
        }
        Collections.sort(mylist, new Comparator<Record>() {
            @Override
            public int compare(Record o1, Record o2) {
                if(o1 == null || o2 == null) return 0;
                return o1.getCount() - o2.getCount();
            }
        });
        for(int i = 0; i < mylist.size(); ++i) {
            Record r = mylist.get(i);
            if(r == null) continue;
            if(r.isRow) {
                for(int p = 0; p < m; ++p) {
                    answer[r.getNumber()][p] = r.getColor();
                }
            } else {
                for(int q = 0; q < n; ++q) {
                    answer[q][r.getNumber()] = r.getColor();
                }
            }
        }
        for(int p = 0; p < n; ++p) {
            for(int q = 0; q < m; ++q) {
                System.out.print(answer[p][q] + " ");
            }
            System.out.println();
        }
    }

    static class Record {
        int color;
        int count;
        boolean isRow;
        int number;

        public Record(int color, int count, boolean isRow, int number) {
            this.color = color;
            this.count = count;
            this.isRow = isRow;
            this.number = number;
        }

        public int getColor() {
            return color;
        }

        public int getCount() {
            return count;
        }

        public void setColor(int color) {
            this.color = color;
        }

        public void setCount(int count) {
            this.count = count;
        }

        public boolean isRow() {
            return isRow;
        }

        public void setIsRow(boolean isRow) {
            this.isRow = isRow;
        }

        public int getNumber() {
            return number;
        }

        public void setNumber(int number) {
            this.number = number;
        }
    }

    static class RecordComparator implements Comparator<Record>{

        @Override
        public int compare(Record o1, Record o2) {
            return o1.count - o2.count;
        }
    }
}
