#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n==2)
	{
		cout<<"1"<<endl<<"1"<<endl;
	}
	else if(n==3)
	{
		cout<<"2"<<endl<<"1 3"<<endl;
	}
	else
	{
		cout<<n<<endl<<"1";
		for(int i=3;i<=n;i+=2)
		{
			cout<<" "<<i;
		}
		for(int i=2;i<=n;i+=2)
		{
			cout<<" "<<i;
		}
		cout<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n==1 || n==2)
	{
		cout<<"1"<<endl<<"1"<<endl;
	}
	else if(n==4)
	{
		cout<<"4"<<endl<<"3 1 4 2"<<endl;
	}
	else if(n==3)
	{
		cout<<"2"<<endl<<"1 3"<<endl;
	}
	else
	{
		cout<<n<<endl;
		for(int i=1;i<=n;i+=2)
		{
			cout<<i<<" ";
		}
		for(int i=2;i<=n;i+=2)
		{
			cout<<i<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{if(n==1)
	{
		cout<<"1"<<endl<<"1"<<endl;
	}
	else if(n==2)
	{
		cout<<"1"<<endl<<"1"<<endl;
	}
	else if(n==3)
	{
		cout<<"2"<<endl<<"1 3"<<endl;
	}
	else
	{
		cout<<n<<endl;
		for(int i=1;i<=n;i+=2)
		{
			cout<<i<<" ";
		}
		for(int i=2;i<=n;i+=2)
		{
			cout<<i<<" ";
		}
		cout<<endl;
	}}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n==1)
	{
		cout<<"1"<<endl<<"1"<<endl;
	}
	else if(n==2)
	{
		cout<<"1"<<endl<<"1"<<endl;
	}
	else if(n==3)
	{
		cout<<"2"<<endl<<"1 3"<<endl;
	}
	else
	{
		cout<<n<<endl<<"1";
		for(int i=3;i<=n;i+=2)
		{
			cout<<" "<<i;
		}
		for(int i=2;i<=n;i+=2)
		{
			cout<<" "<<i;
		}
		cout<<endl;
	}
	return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int main() {

 int x;
 cin>>x;
 if (x==3)cout<<2<<endl<<1<<" "<<3;

   else if(x<=2) cout<<1<<endl<<1;
  else if (x==4) cout<<4<<endl<<3<<" "<<1<<" "<<4<<" "<<2;
  else{

    cout<<x<<endl;
    if(x%2==0){
      for(int i=1;i<x;i+=2){
      cout<<i<<" ";
      }
       for(int i=2;i<=x;i+=2){
      cout<<i<<" ";
      }

      }
       else{
      for(int i=1;i<=x;i+=2){
      cout<<i<<" ";
      }
       for(int i=2;i<x;i+=2){
      cout<<i<<" ";
      }

      }

    }
 return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int main() {

 int x;
 cin>>x;
 if (x==3)cout<<2<<endl<<1<<" "<<3;

   else if(x<=2) cout<<1<<endl<<1;
  else if (x==4) cout<<4<<endl<<1<<" "<<3<<" "<<4<<" "<<2;
  else{

    cout<<x<<endl;
    if(x%2==0){
      for(int i=1;i<x;i+=2){
      cout<<i<<" ";
      }
       for(int i=2;i<=x;i+=2){
      cout<<i<<" ";
      }

      }
       else{
      for(int i=1;i<=x;i+=2){
      cout<<i<<" ";
      }
       for(int i=2;i<x;i+=2){
      cout<<i<<" ";
      }

      }

    }
 return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int main() {

 int x;
 cin>>x;
 if (x==3)cout<<2<<endl<<1<<" "<<3;

   else if(x<=2) cout<<1<<endl<<1;
  else if (x==4) cout<<4<<endl<<1<<" "<<3<<" "<<4<<" "<<2;
  else{

    cout<<x<<endl;
    if(x%2==0){
      for(int i=1;i<x;i+=2){
      cout<<i<<" ";
      }
       for(int i=2;i<=x;i+=2){
      cout<<i<<" ";
      }

      }

      for(int i=1;i<=x;i+=2){
       cout<<i<<" ";
      }
       for(int i=2;i<x;i+=2){
      cout<<i<<" ";

      }

    }
 return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int main() {

 int x;
 cin>>x;
 if (x==3)cout<<2<<endl<<1<<" "<<3;

   else if(x<=2) cout<<1<<endl<<1;
  else if (x==4) cout<<4<<endl<<1<<" "<<3<<" "<<4<<" "<<2;
  else{

    cout<<x<<endl;
    if(x%2==0){
      for(int i=1;i<x;i+=2){
      cout<<i<<" ";
      }
       for(int i=2;i<=x;i+=2){
      cout<<i<<" ";
      }

      }

      for(int i=1;i<=x;i+=2){
      cout<<i<<" ";
      }
       for(int i=2;i<x;i+=2){
      cout<<i<<" ";

      }

    }
 return 0;
}


#include <iostream>

using namespace std;

void main()
{
    int n;
    cin >> n;
    if (n > 4)
    {
        cout << n << endl;
        for (int i = 1; i <= n; i += 2)
            cout << i << " ";
        for (int i = 2; i <= n; i += 2)
            cout << i << " ";
        cout << endl;
        return;
    }
    if (n == 4)
    {
        cout << n << endl << 2 << " " << 4 << " " << 1 << " " << 3 << endl;
        return;
    }
    if (n == 3)
    {
        cout << n - 1 << endl << 1 << " " << 3 << endl;
        return;
    }
    if (n == 2)
    {
        cout << n - 1 << endl << 1 << endl;
        return;
    }
    if (n == 1)
    {
        cout << 1 << endl << 1 << endl;
        return;
    }

}


#include <iostream>

using namespace std;

void main()
{
    int n;
    cin >> n;
    if (n > 4)
    {
        cout << n << endl;
        for (int i = 1; i <= n; i += 2)
            cout << i << " ";
        for (int i = 2; i <= n; i += 2)
            cout << i << " ";
        cout << endl;
        system("pause");
        return;
    }
    if (n == 4)
    {
        cout << n - 1 << endl << 1 << " " << 4 << " " << 2 << endl;
        return;
    }
    if (n == 3)
    {
        cout << n - 1 << endl << 1 << " " << 3 << endl;
    }
    if (n == 2)
    {
        cout << n - 1 << endl << 1 << endl;
        return;
    }
    if (n == 1)
    {
        cout << 1 << endl << 1 << endl;
        return;
    }

}


#include <iostream>

using namespace std;

void main()
{
    int n;
    cin >> n;
    if (n > 4)
    {
        cout << n << endl;
        for (int i = 1; i <= n; i += 2)
            cout << i << " ";
        for (int i = 2; i <= n; i += 2)
            cout << i << " ";
        cout << endl;
        system("pause");
        return;
    }
    if (n == 4)
    {
        cout << n << endl << 2 << " " << 4 << " " << 1 << " " << 3 << endl;
        return;
    }
    if (n == 3)
    {
        cout << n - 1 << endl << 1 << " " << 3 << endl;
        return;
    }
    if (n == 2)
    {
        cout << n - 1 << endl << 1 << endl;
        return;
    }
    if (n == 1)
    {
        cout << 1 << endl << 1 << endl;
        return;
    }

}


#include <iostream>

using namespace std;

void main()
{
    int n;
    cin >> n;
    if (n > 4)
    {
        cout << n << endl;
        for (int i = 1; i <= n; i += 2)
            cout << i << " ";
        for (int i = 2; i <= n; i += 2)
            cout << i << " ";
        cout << endl;
        return;
    }
    if (n == 4)
    {
        cout << n - 1 << endl << 1 << " " << 4 << " " << 2 << endl;
        return;
    }
    if (n == 3)
    {
        cout << n - 1 << endl << 1 << " " << 3 << endl;
        return;
    }
    if (n == 2)
    {
        cout << n - 1 << endl << 1 << endl;
        return;
    }
    if (n == 1)
    {
        cout << 1 << endl << 1 << endl;
        return;
    }

}


#include <iostream>

using namespace std;

void main()
{
    int n;
    cin >> n;
    if (n > 4)
    {
        cout << n << endl;
        for (int i = 1; i <= n; i += 2)
            cout << i << " ";
        for (int i = 2; i <= n; i += 2)
            cout << i << " ";
        cout << endl;
        system("pause");
        return;
    }
    if (n == 4)
    {
        cout << n - 1 << endl << 1 << 4 << 2 << endl;
        return;
    }
    if (n == 3)
    {
        cout << n - 1 << endl << 1 << 3 << endl;
    }
    if (n == 2)
    {
        cout << n - 1 << endl << 1 << endl;
        return;
    }
    if (n == 1)
    {
        cout << 1 << endl << 1 << endl;
        return;
    }

}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stdlib.h>
using namespace std;

int main()
{
	int arr[5010],res[5010],n,index=0,ans=0;
	cin >> n;
	for(int i=0;i<n;i++)
		arr[i]=i+1;
	if(n==1 || n==2)
		cout << 1 << endl << 1 << endl;
	else if(n==3)
		printf("2\n1 3\n");
	else if(n==4)
		printf("4\n1 3 4 2\n");
	else
	{
		for(int i=0;i<n;i++)
		{
			if(i%2==1)
			{res[index++]=arr[i];ans++;}
		}
		for(int i=0;i<n;i++)
		{
			if(i%2==0)
			{res[index++]=arr[i];ans++;}
		}
		cout << ans << endl;
		for(int i=0;i<index;i++)
			printf("%d ",res[i]);
	}
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stdlib.h>
using namespace std;

int main()
{
	int arr[5010],res[5010],n,index=0,ans=0;
	cin >> n;
	for(int i=0;i<n;i++)
		arr[i]=i+1;
	if(n==1 || n==2)
		cout << 1 << endl << 1 << endl;
	else if(n==3)
		printf("2\n1 3\n");
	else if(n==4)
		printf("4\n3 1 4 2\n");
	else
	{
		for(int i=0;i<n;i++)
		{
			if(i%2==1)
			{res[index++]=arr[i];ans++;}
		}
		for(int i=0;i<n;i++)
		{
			if(i%2==0)
			{res[index++]=arr[i];ans++;}
		}
		cout << ans << endl;
		for(int i=0;i<index;i++)
			printf("%d ",res[i]);
	}
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;

int main()
{
    int arr[5010];
    int num,i,cnt=0,res=1;
    cin >> num;
    for(i=0; res<=num; i++)
    {
        arr[i]=res;
        res+=2;
        cnt++;
    }
    res=2;
    if(arr[i-1]!=res-1 && arr[i-1]!=res+1)
    {
        for(;res<=num;i++)
    {
        arr[i]=res;
        res+=2;
        cnt++;
    }
    }

    printf("%d\n",cnt);
    for(i=0;i<cnt;i++)
    {
    printf("%d ",arr[i]);
    }
    printf("\n");
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;

int main()
{
    int arr[5010];
    int num,i,cnt=0,res=1;
    cin >> num;
    for(i=0; res<=num; i++)
    {
        arr[i]=res;
        res+=2;
        cnt++;
    }
    res=2;
    if(arr[i-1]!=3)
    {
        for(;res<=num;i++)
    {
        arr[i]=res;
        res+=2;
        cnt++;
    }
    }

    printf("%d\n",cnt);
    for(i=0;i<cnt;i++)
    {
    printf("%d ",arr[i]);
    }
    printf("\n");
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <map>
#include <sstream>
#include <complex>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <deque>
#include <bitset>

#define vrep(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,a,b) for(int i=a;i<b;i++)
#define vrrep(i,a,b) for(int i=a;i>=b;i--)
#define mzero(mem) memset((mem),0,sizeof(mem))
#define mset(mem,v) memset((mem),v,sizeof(mem))
#define all(v) (v).begin(),(v).end()
#define LL  long long
#define pii pair<int,int>

using namespace std;
typedef vector<int> vi;

//#define ONLINE_JUDGE

#define OO (123456789)

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    int n;
    cin>>n;

    if(n==1)
        cout<<"1\n1";
    if(n==2)
        cout<<"1\n1";
    if(n==3)
        cout<<"2\n1 3";
    if(n==4)
        cout<<"3\n1 4 2";
    else
    {
        cout<<n<<endl;
        int x=1;
        do{ cout<<x<<" "; x+=2;}while(x<n);
        x=2;
        do{ cout<<x<<" "; x+=2;}while(x<n);
    }
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <map>
#include <sstream>
#include <complex>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <deque>
#include <bitset>

#define vrep(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,a,b) for(int i=a;i<b;i++)
#define vrrep(i,a,b) for(int i=a;i>=b;i--)
#define mzero(mem) memset((mem),0,sizeof(mem))
#define mset(mem,v) memset((mem),v,sizeof(mem))
#define all(v) (v).begin(),(v).end()
#define LL  long long
#define pii pair<int,int>

using namespace std;
typedef vector<int> vi;

//#define ONLINE_JUDGE

#define OO (123456789)

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    int n;
    cin>>n;

    if(n==1)
        cout<<"1\n1";
    else if(n==2)
        cout<<"1\n1";
    else if(n==3)
        cout<<"2\n1 3";
    else if(n==4)
        cout<<"3\n1 4 2";
    else
    {
        cout<<n<<endl;
        int x=1;
        do{ cout<<x<<" "; x+=2;}while(x<=n);
        x=2;
        do{ cout<<x<<" "; x+=2;}while(x<=n);
    }
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <map>
#include <sstream>
#include <complex>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <deque>
#include <bitset>

#define vrep(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,a,b) for(int i=a;i<b;i++)
#define vrrep(i,a,b) for(int i=a;i>=b;i--)
#define mzero(mem) memset((mem),0,sizeof(mem))
#define mset(mem,v) memset((mem),v,sizeof(mem))
#define all(v) (v).begin(),(v).end()
#define LL  long long
#define pii pair<int,int>

using namespace std;
typedef vector<int> vi;

//#define ONLINE_JUDGE

#define OO (123456789)

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    int n;
    cin>>n;

    if(n==1)
        cout<<"1\n1";
    if(n==2)
        cout<<"1\n1";
    if(n==3)
        cout<<"2\n1 3";
    if(n==4)
        cout<<"3\n1 4 2";
    else
    {
        cout<<n<<endl;
        int x=1;
        do{ cout<<x<<" "; x+=2;}while(x<=n);
        x=2;
        do{ cout<<x<<" "; x+=2;}while(x<=n);
    }
}


import math

def solve(n, x):
    if n < 3:
        return 1
    f = n // x
    if n > f * x + 2:
        return 2 + f
    return 1 + f

if __name__=='__main__':
    for _ in range(int(input().strip())):
        n, x = map(int, input().strip().split())
        print(solve(n, x))


def solve(n, x):
    if n < 3:
        return 1
    first_flat_on_floor = 3
    floor = 2
    while n > first_flat_on_floor + x - 1:
        first_flat_on_floor += x
        floor += 1
    return floor

if __name__=='__main__':
    for _ in range(int(input().strip())):
        n, x = map(int, input().strip().split())
        print(solve(n, x))


import math

def solve(n, x):
    if x == 1:
        return max(1, x - 2)
    f = n // x
    if n > f * x + 2:
        return 2 + f
    return 1 + f

if __name__=='__main__':
    for _ in range(int(input().strip())):
        n, x = map(int, input().strip().split())
        print(solve(n, x))


t=int(input())
for i in range(t):
    n,x=map(int, input().split())
    y=n/x
    a=int(y)+1
    print(a)


import math
t=int(input())
for i in range(t):
    n,x=map(int, input().split())
    y=n/x
    a=math.ceil(y)+1
    print(a)


import math
t=int(input())
for i in range(t):
    n,x=map(int, input().split())
    y=n/x
    a=math.floor(y)+1
    print(a)


t=int(input())
for i in range(t):
    n,x=map(int, input().split())
    y=n/x
    a=round(y)+1
    print(a)


import math
t=int(input())
for i in range(t):
    n,x=map(int, input().split())
    y=n/x
    a=math.trunc(y)+1
    print(a)


import numpy
t=int(input())
for i in range(t):
    n,x=map(int, input().split())
    y=n/x
    a=numpy.rint(y)+1
    print(a)


t = int(input())
for i in range(t):
    n, x = map(int, input().split())
    f = 1
    a = 2
    while a < n:
        a += x
        f += 1
    print(f)


for j in range(int(input)):
    n,x=map(int,input().split())
    if n<=2:
        print(1)
    else:
        for i in range(n):
            if n>=i*x+3 and n<=(i*x)+3+(x-1):
                print(i+2)


for w in range(int(input())):
    n,m=map(int,input().split())
    count=0
    for i in range(n):
        a,b=map(int,input().split())
        c,d=map(int,input().split())
        if b==c:
            count+=1
    if count>=1 and m%2==0:
        print('YES')
    else:
        print('NO')


for j in range(int(input())):
    n,x=map(int,input().split())
    if n<=2:
        print(1)
    else:
        for i in range(n):
            if n>=i*x+3 and n<=(i*x)+3+(x-1):
                print(i+2)
                break


n,x=map(int,input().split())
if n<=2:
    print(1)
else:
    for i in range(n):
        if n>=i*x+3 and n<=(i*x)+3+(x-1):
            print(i+2)


import math
def ques1(n,x):
    if n<= 2:
        return n
    if n <= x:
        return 2
    k = (n-2)/x
    k1 = math.ceil(k)
    return 1 + k1

t = int(input())
for i in range(t):
    n,x = [int(i) for i in input().split()]
    ans = ques1(n,x)
    print(ans)


import math
def ques1(n,x):
    if n<= 2:
        return n
    k = (n-2)/x
    k1 = math.ceil(k)
    return 1 + k1

t = int(input())
for i in range(t):
    n,x = [int(i) for i in input().split()]
    ans = ques1(n,x)
    print(ans)


import math
def ques1(n,x):
    if n <= x:
        return 1
    if n<= 2:
        return n
    k = (n-2)/x
    k1 = math.ceil(k)
    return 1 + k1

t = int(input())
for i in range(t):
    n,x = [int(i) for i in input().split()]
    ans = ques1(n,x)
    print(ans)


import math
def ques1(n,x):
    if n<= 2:
        return 1
    if n <= x:
        return 2
    k = (n-2)/x
    k1 = math.ceil(k)
    return 1 + k1

t = int(input())
for i in range(t):
    n,x = [int(i) for i in input().split()]
    ans = ques1(n,x)
    print(ans)


a = int(input())
for i in range(a):
    n, x = map(int, input().split())
    if n==1:
        n=2
    print((-1*((-1*(n-2))//x))+1)


a = int(input())
for i in range(a):
    n, x = map(int, input().split())
    if n=1:
        n=2
    print((-1*((-1*(n-2))//x))+1)


a = int(input())
for i in range(a):
    n, x = map(int, input().split())
    print(-((-(n-2))//x)+1)


a = int(input())
for i in range(a):
    n, x = map(int, input().split())
    print(((n-2)+x-1)//x+1)


import math
t=int(input())
for _ in range(t):
    f,r=map(int,input().split())
    print(math.ceil(f/r))


import math
t=int(input())
for _ in range(t):
    f,r=map(int,input().split())
    if f<=2:
        x=1
    else:
        x=math.ceil((f-2)/r)+1
    print(x)


import math
t=int(input())
for _ in range(t):
    f,r=map(int(nput().split())
    print(ceil(f/r))


import math
t=int(input())
for _ in range(t):
    f,r=map(int(nput().split())
    print(math.ceil(f/r))


import math
t=int(input())
for _ in range(t):
    f,r=map(int,input().split())
    x=math.ceil((f-2)/r)+1
    print(x)


def solution():
    t = int(input())
    for i in range(t):
        n, x = [int(i) for i in input().split()]
        res = n // x + 1
        if n % x > 2:
            res += 1
        print(res)

if __name__ == '__main__':
    solution()


def solution():
    t = int(input())
    for i in range(t):
        n, x = [int(i) for i in input().split()]
        if n <= 2:
            print(1)
        else:
            n -= 2
            res = n // x + 1
            if n % x > 0:
                res += 1
            print(res)

if __name__ == '__main__':
    solution()


def solution():
    t = int(input())
    for i in range(t):
        n, x = [int(i) for i in input().split()]
        if n <= 2:
            print(1)
        else:
            n -= 2
            print(n // x + 1)

if __name__ == '__main__':
    solution()


def solution():
    t = int(input())
    for i in range(t):
        n, x = [int(i) for i in input().split()]
        if n > 2:
            res = n // x + 1
            if n % x > 2:
                res += 1
        elif x == 1:
            res = max(1, n - 2)
        elif x == 2:
            res = max(1, (n - 1) // 2)
        print(res)

if __name__ == '__main__':
    solution()


def solution():
    t = int(input())
    for i in range(t):
        n, x = [int(i) for i in input().split()]
        if x > 2:
            res = n // x + 1
            if n % x > 2:
                res += 1
        elif x == 1:
            res = max(1, n - 2)
        elif x == 2:
            res = max(1, (n - 1) // 2)
        print(res)

if __name__ == '__main__':
    solution()


t = int(input())

for _ in range(t):
    n, x = map(int, input().split())
    count = 1
    if n <= 2:
        print(1)
    else:
        for i in range(3, n, x):
            count += 1
        print(count)


t = int(input())

for _ in range(t):
    n, x = map(int, input().split())
    count = 1
    if n <= 2:
        print(1)
    else:
        rem = (n-2) % x
        count += (n - 2) // x
        if rem > 0:
            count += 1
        print(count)


t = int(input())

for _ in range(t):
    n, x = map(int, input().split())
    n -= 2
    if n <= 0:
        print(1)
    else:
        print(round(n / x) + 1)


t = int(input())

for _ in range(t):
    n, x = map(int, input().split())
    count = 1
    if n <= 2:
        print(1)
    else:
        count += round((n - 2) / x)
        print(count)


t = int(input())

for _ in range(t):
    n, x = map(int, input().split())
    count = 1
    if n <= 2:
        print(1)
    else:
        for i in range(3, n + 1, x):
            count += 1
        print(count)


from math import ceil
for _ in range(int(input())):
    number, x = map(int, input().split())
if number - 2 > 0:
    print(ceil((number - 2) / x) + 1)
else:
    print(1)


from math import ceil
for _ in range(int(input())):
    number, x = map(int, input().split())
    if number - 2 > 0:
        print(ceil((number - 2) / x) + 1)
    else:
        print(1)


from Math import ceil
for _ in range(int(input()):
    number, x = map(int, input().split())
    if number - 2 > 0:
        print(Math.ceil((number - 2) / x) + 1)
    else:
        print(1)


from Math import ceil
for _ in range(int(input())):
    number, x = map(int, input().split())
    if number - 2 > 0:
        print(Math.ceil((number - 2) / x) + 1)
    else:
        print(1)


from math import ceil

t = int(input())
for _ in range(t):
	n, x = map(int, input().split())
	n -= 2
	print(ceil(n / x) + 1)


from math import ceil

t = int(input())
for _ in range(t):
	n, x = map(int, input().split())
	if n <= 2:
		print(1)
	else:
		print(ceil(n / x) + 1)


from math import ceil

t = int(input())
for _ in range(t):
	n, x = map(int, input().split())
	n -= 2
	print(ceil((n - 2) / x) + 1)


from math import ceil

t = int(input())
for _ in range(t):
	n, x = map(int, input().split())
	if n <= 2:
		print(1)
	else:
		n -= 2
		print(ceil(n / x) + 1)


for t in range(int(input())):
    n,x = map(int,input().split())
    if n == 1 or n==2:
        print(1)
    else:
        for i in range(2,1001):
            s = (i-2)*x + 3
            e = (i-1)*x + 2
            if s<=n<=e:
                print(i)
                break


for t in range(int(input())):
    n,x = map(int,input().split())
    i = (n-2+x)/x
    if i > int(i):
    	i = int(i)+1
    else:
    	i = int(i)
    print(i)


for t in range(int(input())):
    n,x = map(int,input().split())
    if n<=2:
        print(1)
    else:
        i = (n-2+x)/x
        if i > int(i):
        	i = int(i)+1
        else:
        	i = int(i)
        print(i)


for t in range(int(input())):
    n,x = map(int,input().split())
    for i in range(1,n+1):
        s = (n-2)*x + 3
        e = (n-1)*x + 2
        if s<=x<=e:
            print(i)
            break


for t in range(int(input()):
    n,x = map(int,input().split())
    for i in range(1,n+1):
        s = (n-2)*x + 3
        e = (n-1)*x + 2
        if s<=x<=e:
            print(i)
            break


for t in range(int(input())):
    n,x = map(int,input().split())
    if n == 1 or n==2:
        print(1)
    else:
        for i in range(2,int(1000/x)+2):
            s = (i-2)*x + 3
            e = (i-1)*x + 2
            if s<=n<=e:
                print(i)
                break


from math import ceil
t = int(input())
for _ in range(t):
    n, x = map(int, input().split())
    print(ceil((n+x-min(x, 2))/x))


t = int(input())
for _ in range(t):
    n, x = map(int, input().split())
    if n<=2:
        print(1)
    else:
        print(ceil((n+x-min(x, 2))/x))


from math import ceil
t = int(input())
for _ in range(t):
    n, x = map(int, input().split())
    if n==x==1:
        print(0)
    else:
        print(ceil((n+x-min(x, 2))/x))


from math import ceil
t = int(input())
for _ in range(t):
    n, x = map(int, input().split())
    if n<=2:
        print(1)
    else:
        print(ceil((n+x-min(x, 2))/x))


from math import ceil
t = int(input())
for _ in range(t):
    n, x = map(int, input().split())
    if n<=2:
        print(1)
    else:
        print(ceil((n+x-2)/x))


t = int(input())
for _ in range(t):
    n, x = map(int, input().split())
    if n==x==1:
        print(0)
    else:
        print(ceil((n+x-min(x, 2))/x))


from math import ceil
t = int(input())
for _ in range(t):
    n, x = map(int, input().split())
    print(ceil((n+x-2)/x))


import math
for _ in range(int(input())):
    nx = list(map(int,input().split()))
    n=nx[0]
    x=nx[1]
    print(math.ceil(((n-3)+1*x)/x))


import math
for _ in range(int(input())):
    nx = list(map(int,input().split()))
    n=nx[0]
    x=nx[1]
    if n==1 or n==2:
        print("1")
    if n>2 and n<=x:
        print("2")
    else:
          print(math.ceil(((n-2)+1*x)/x))


import math
for _ in range(int(input())):
    nx = list(map(int,input().split()))
    n=nx[0]
    x=nx[1]
    print(math.floor(((n-3)+2*x)/x))


import math
for _ in range(int(input())):
    nx = list(map(int,input().split()))
    n=nx[0]
    x=nx[1]
    if n==1 or n==2:
        print("1")
    elif n>2 and n<=x:
        print("2")
    else:
          print(math.ceil(((n-2)+1*x)/x))


import math
for _ in range(int(input())):
    nx = list(map(int,input().split()))
    n=nx[0]
    x=nx[1]
    print(math.ceil(((n-2)+1*x)/x))


import math
for _ in range(int(input())):
    nx = list(map(int,input().split()))
    n=nx[0]
    x=nx[1]
    if n==1 or n==2:
        print("2")
    if n>2 and n<=x:
        print("2")
    else:
          print(math.ceil(((n-2)+1*x)/x))


a = int(input())
for i in range(a):
    n, x = map(int, input().split())
    count = 1
    if n <= 2:
        print(1)
        break
    n = n - 2
    if n % x != 0:
        count = count + 1
    print(count + (n // x))


n = int(input())
x = int(input())
count = 1
n = n - 2
if n % x != 0:
    count += 1
print(count + (n // x))


a = int(input())
for i in range(a):
    n, x = map(int, input().split())
    count = 1
    if n - 2 > 0:
        count = count + (n - 2) // x
        n = n - 2
        if n % x > 0:
            count = count + 1
    print(count)


a = int(input())
for i in range(a):
    n, x = map(int, input().split())
    count = 1
    n = n - 2
    if n % x != 0:
        count += 1
    print(count + (n // x))


t = int(input())
for i in range(t):
    n, x = map(int, input().split())
    if x <= 2:
        print('1')
    else:
        a = (n - 3) % x
        print(a + 2)


t = int(input())
for i in range(t):
    n, x = map(int, input().split())
    if n <= 2:
        print(1)
    else:
        a = (n - 3) // x
        print(a + 2)


t = int(input())
for i in range(t):
    n, x = map(int, input().split())
    if x <= 2:
        print(1)
    else:
        a = (n - 3) // x
        print(a + 2)


t = int(input())
for i in range(t):
    n, x = map(int, input().split())
    if x <= 2:
        print('1')
    else:
        a = (n - 3) / x
        print(round(a) + 2)


t = int(input())
for i in range(t):
    n, x = map(int, input().split())
    if x <= 2:
        print('1')
    else:
        a = (n - 3) // x
        print(a + 2)


import math
for _ in range(int(input())):
    n,x=map(int,input().split())
    t=n/x
    print(round(t)+1)


import math
for _ in range(int(input())):
    n,x=map(int,input().split())
    t=(n-1)/x
    print(round(t)+1)


for i in range(int(input())):
    n, x = map(int, input().split())
    print(1 if n <= 2 else (n - 3) // x + 2)


import math
for _ in range(int(input())):
    n,x=map(int,input().split())
    t=n/x
    print(math.ceil(t)+1)


t = int(input())
while(t>0):
    t=t-1
    n,x = map(int,input().split())
    if n == 1 or n == 2:
        print(1)
    else:
        z = 2
        c = 1
        while(True):
            z=z+x
            c= c+1
            if z>=n:
                break
        print(c)


t = int(input())
while(t>0):
    t=t-1
    n,x = map(int,input().split())
    if n == 1 or n == 2:
        print(1)
    else:
        z = 3
        c = 1
        while(True):
            z=z+x
            c= c+1
            if z>=n:
                break
        print(c)


t = int(input())
while(t>0):
    t=t-1
    n,x = map(int,input().split())
    if n == 1 or n == 2:
        print(1):
    else:
        z = 1
        while(z>=n):
            z=z+x
        print(z)


t = int(input())
while(t>0):
    t=t-1
    n,x = map(int,input().split())
    if n == 1 or n == 2:
        print(1)
    else:
        z = 1
        while(z>=n):
            z=z+x
        print(z)


t=int(input())
while t>0:
	n,x=list(map(int,input().split()))
	apartment=1
	i=0
	if n==1 or n==2:
    	print(apartment)
	else:
    	if n in range(3,x+2+1):
        	apartment=2
        	print(apartment)
    	while(True):
        	i=i+1
        	apartment=apartment+1
        	if n in range((i-1)*x+3,i*x+2+1):
            	print(apartment)
            	break
	t=t-1


t=int(input())
while t>0:
    n,x=list(map(int,input().split()))
    apartment=1
    i=0
    if n==1 or n==2:
        print(apartment,end=" ")
    else:
        if n in range(3,x+2+1):
            apartment=2
            print(apartment,end=" ")
        else:
            while(True):
                i=i+1
                apartment=apartment+1
                if n in range((i-1)*x+3,i*x+2+1):
                    print(apartment,end=" ")
                    break
    t=t-1


t=int(input())
while t>0:
    n,x=list(map(int,input().split()))
    apartment=1
    i=0
    if n==1 or n==2:
        print(apartment)
    else:
        if n in range(3,x+2+1):
            apartment=2
            print(apartment)
        while(True):
            i=i+1
            apartment=apartment+1
            if n in range((i-1)*x+3,i*x+2+1):
                print(apartment)
                break
    t=t-1


t=int(input())
while t>0:
    n,x=list(map(int,input().split()))
    apartment=1
    i=0
    if n==1 or n==2:
        print(apartment,end=" ")
    else:
        if n in range(3,x+2+1):
            apartment=2
            print(apartment,end=" ")
        while(True):
            i=i+1
            apartment=apartment+1
            if n in range((i-1)*x+3,i*x+2+1):
                print(apartment,end=" ")
                break
    t=t-1


q=int(input())
for i in range (q):
    b,a=map(int,input().split())
    if b==1 or b==2:
        print(1)
    else:
        b=b-3+a
        c=b//a + 1
        print(c)


q=int(input())
for i in range (q):
    a,b=map(int,input().split())
    c=(b-2)//a +1
    print(c)


q=int(input())
for i in range (q):
    b,a=map(int,input().split())
    if b==1 or b==2:
        print(1)
    else:
        b=b-3+a
        c=b//a
        print(c)


q=int(input())
for i in range (q):
    b,a=map(int,input().split())
    c=(b-2)//a +1
    print(c)


q=int(input())
for i in range (q):
    b,a=map(int,input().split())
    c=(b-3+2*a)//a
    print(c)


q=int(input())
for i in range (q):
    a,b=map(int.input(),split())
    c=(b-2)//a +1
    print(c)


q=int(input())
for i in range (q):
    b,a=map(int,input().split())
    c=(b-3)//a +2
    print(c)


q=int(input())
for i in range (q):
    b,a=map(int,input().split())
    c=(b-2)//a +2
    print(c)


casos = int(input())

for i in range(casos):
	lista = []
	for j in input().split(" "):
		lista.append(int(j))

	plantas = 1
	if lista[0] > 3:
		lista[0] -= 2
		while lista[0] > 0:
			lista[0] -= lista[1]
			plantas += 1
	print(plantas)


casos = int(input())

for i in range(casos):
	lista = []
	for j in input().split(" "):
		lista.append(int(j))

	if lista[0] <= 2:
		print(1)
	else:
		planta = 1
		lista[0] -= 2
		planta += (lista[0]/lista[1])
		if lista[0]%lista[1]!=0:
			planta += 1
		print(int(planta))


casos = int(input())

for i in range(casos):
	lista = []
	for j in input().split(" "):
		lista.append(int(j))

	plantas = (lista[0]-2) / lista[1]
	if (lista[0]-2) % lista[1] > 0:
		print(int(plantas+2))
	else:
		print(int(plantas+1))


casos = int(input())

for i in range(casos):
	lista = []
	for j in input().split(" "):
		lista.append(int(j))
	planta = 0
	plantas = (lista[0]-2) / lista[1]
	print(int(plantas+1.99))


import math
for _ in range(int(input())):
    net,one = map(int,input().split())
    net-=2
    print(math.ceil(net/one)+1)


import math
for _ in range(int(input())):
    net,one = map(int,input().split())
    net-=2
    print(math.ceil(net/one))


#include <iostream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

using namespace std;
int color[5001][5001]={0};
int vis[5001][5001]={0};
int main()
{
  long n, m, k;
  long type, r, c,a;
  cin >> n >> m >> k;
  long long num=0, thre= n*m;
  long **command = new long*[k];

  for(int i = 0; i  < k; i++)
  	command[i] = new long[3];

  for(int i = 0; i < k; i++)
  {
  	cin >> command[i][0] >> command[i][1] >> command[i][2];
  }

  	for(int i = k-1; i >=0 && num < thre; i--)
  	{
  		type = command[i][0];
  		if (type == 1)
  		{
  			r = command[i][1];
  			a = command[i][2];
  			for(int j = 0; j < m; j++)//cols
  			{
  				if (!vis[r-1][j])
  				{
  					color[r-1][j] =  a;
  					num++;
  					vis[r-1][j] = 1;
  				}
  			}

  		}

  		else {
  				c = command[i][1];
  				a = command[i][2];
  				for(int j = 0; j < n; j++)//rows
  				{
  					if (!vis[j][c-1])
  					{
  						color[j][c-1] =  a;
  						num++;
  						vis[j][c-1] = 1;
  					}
  				}
  			}

  	}

  for(int i = 0; i < n; i++){
  	for(int j = 0; j < m; j++)
  		cout << color[i][j] <<" ";

  	cout << endl;

  }

  return 0;
}


#include <iostream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

using namespace std;
int color[5010][5010];
int vis[5010][5010];
long command[100010][3];
long long donerow[5010]={0};
long long donecol[5010]={0};

int main()
{
  long long n, m, k;
  long  long type, r, c,a;
  scanf("%lld%lld%lld", &n, &m, &k);
  long long num=0, rr = 0, cc = 0, thre = n*m;
  memset(vis, 0, sizeof(vis) );
  memset(color, 0, sizeof(color) );

  for(long  long i = 0; i < k; i++)
  {
    scanf("%ld%ld%ld", &command[i][0], &command[i][1],&command[i][2]);
  }

  	for(long  long i = k-1; i >=0 && num < thre; i--)
  	{

  		if (command[i][0] == 1)
  		{
  			if (donecol[command[i][1] ])
  				continue;
  			donecol[ command[i][1] ]=1;
  			for(long long j = 0; j < m; j++)//cols
  			{
  				if (!vis[ command[i][1]-1 ][j])
  				{
  					color[ command[i][1]-1 ][j] =  command[i][2];
  					num++;
  					vis[ command[i][1]-1 ][j] = 1;
  				}
  			}

  		}

  		else {
  				if (donerow[command[i][1] ])
  					continue;
  				donerow[ command[i][1] ] = 1;
  				for(long long j = 0; j < n; j++)//rows
  				{
  					if (!vis[j][ command[i][1]-1 ] )
  					{
  						color[j][ command[i][1]-1 ] =  command[i][2];
  						num++;
  						vis[j][ command[i][1]-1 ] = 1;
  					}
  				}
  			}

  	}

  for(long long i = 0; i < n; i++){
  	for(long long j = 0; j < m; j++)
  		printf("%d ",color[i][j]);

  	cout << endl;

  }

  return 0;
}


#include <iostream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

using namespace std;
int color[5010][5010];
int vis[5010][5010];
long command[100010][3];
long long donerow[5010]={0};
long long donecol[5010]={0};

int main()
{
  long long n, m, k;
  long  long type, r, c,a;
  scanf("%I64d%I64d%I64d ", &n, &m, &k);
  long long num=0, rr = 0, cc = 0, thre = n*m;
  memset(vis, 0, sizeof(vis) );
  memset(color, 0, sizeof(color) );

  for(long  long i = 0; i < k; i++)
  {
    scanf("%ld%ld%ld", &command[i][0], &command[i][1],&command[i][2]);
  }

  	for(long  long i = k-1; i >=0 && num < thre; i--)
  	{

  		if (command[i][0] == 1)
  		{
  			if (donecol[command[i][1] ])
  				continue;
  			donecol[ command[i][1] ]=1;
  			for(long long j = 0; j < m; j++)//cols
  			{
  				if (!vis[ command[i][1]-1 ][j])
  				{
  					color[ command[i][1]-1 ][j] =  command[i][2];
  					num++;
  					vis[ command[i][1]-1 ][j] = 1;
  				}
  			}

  		}

  		else {
  				if (donerow[command[i][1] ])
  					continue;
  				donerow[ command[i][1] ] = 1;
  				for(long long j = 0; j < n; j++)//rows
  				{
  					if (!vis[j][ command[i][1]-1 ] )
  					{
  						color[j][ command[i][1]-1 ] =  command[i][2];
  						num++;
  						vis[j][ command[i][1]-1 ] = 1;
  					}
  				}
  			}

  	}

  for(long long i = 0; i < n; i++){
  	for(long long j = 0; j < m; j++)
  		printf("%d ",color[i][j]);

  	cout << endl;

  }

  return 0;
}


#include <iostream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

using namespace std;
int color[5001][5001]={0};
int vis[5001][5001]={0};
long command[100001][3];

int main()
{
  long long n, m, k;
  long  long type, r, c,a;
  cin >> n >> m >> k;
  long long num=0, thre= n*m;

  for(long  long i = 0; i < k; i++)
  {
  	cin >> command[i][0] >> command[i][1] >> command[i][2];
  }

  	for(long  long i = k-1; i >=0 && num < thre; i--)
  	{

  		if (command[i][0] == 1)
  		{

  			for(long long j = 0; j < m; j++)//cols
  			{
  				if (!vis[ command[i][1]-1 ][j])
  				{
  					color[ command[i][1]-1 ][j] =  command[i][2];
  					num++;
  					vis[ command[i][1]-1 ][j] = 1;
  				}
  			}

  		}

  		else {
  				for(long long j = 0; j < n; j++)//rows
  				{
  					if (!vis[j][ command[i][1]-1 ] )
  					{
  						color[j][ command[i][1]-1 ] =  command[i][2];
  						num++;
  						vis[j][ command[i][1]-1 ] = 1;
  					}
  				}
  			}

  	}

  for(long long i = 0; i < n; i++){
  	for(long long j = 0; j < m; j++)
  		cout << color[i][j] <<" ";

  	cout << endl;

  }

  return 0;
}


#include <iostream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

using namespace std;
int color[5010][5010];
int vis[5010][5010];
long command[100010][3];
long long donerow[5010]={0};
long long donecol[5010]={0};

int main()
{
  long long n, m, k;
  long  long type, r, c,a;
  cin >> n >> m >> k;
  long long num=0, rr = 0, cc = 0;
  memset(vis, 0, sizeof(vis) );
  memset(color, 0, sizeof(color) );

  for(long  long i = 0; i < k; i++)
  {
  	cin >> command[i][0] >> command[i][1] >> command[i][2];
  }

  	for(long  long i = k-1; i >=0 && rr < n && cc < m  && num < thre; i--)
  	{

  		if (command[i][0] == 1)
  		{
  			if (donecol[i])
  				continue;
  			for(long long j = 0; j < m; j++)//cols
  			{
  				if (!vis[ command[i][1]-1 ][j])
  				{
  					color[ command[i][1]-1 ][j] =  command[i][2];
  					num++;
  					donecol[i]=1;
  					vis[ command[i][1]-1 ][j] = 1;
  				}
  			}

  		}

  		else {
  				if (donerow[i])
  					continue;
  				for(long long j = 0; j < n; j++)//rows
  				{
  					if (!vis[j][ command[i][1]-1 ] )
  					{
  						color[j][ command[i][1]-1 ] =  command[i][2];
  						num++;
  						donerow[i] = 1;
  						vis[j][ command[i][1]-1 ] = 1;
  					}
  				}
  			}

  	}

  for(long long i = 0; i < n; i++){
  	for(long long j = 0; j < m; j++)
  		cout << color[i][j] <<" ";

  	cout << endl;

  }

  return 0;
}


#include <iostream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

using namespace std;
int color[5010][5010];
int vis[5010][5010];
long command[100010][3];
long long donerow[5010]={0};
long long donecol[5010]={0};

int main()
{
  long long n, m, k;
  long  long type, r, c,a;
  cin >> n >> m >> k;
  long long num=0, thre= n*m;
  memset(vis, 0, sizeof(vis) );
  memset(color, 0, sizeof(color) );

  for(long  long i = 0; i < k; i++)
  {
  	cin >> command[i][0] >> command[i][1] >> command[i][2];
  }

  	for(long  long i = k-1; i >=0 && num < thre; i--)
  	{

  		if (command[i][0] == 1)
  		{
  			if (donecol[i] == m)
  				continue;
  			for(long long j = 0; j < m; j++)//cols
  			{
  				if (!vis[ command[i][1]-1 ][j])
  				{
  					color[ command[i][1]-1 ][j] =  command[i][2];
  					num++;
  					donecol[i]++;
  					vis[ command[i][1]-1 ][j] = 1;
  				}
  			}

  		}

  		else {
  				if (donerow[i] == n)
  					continue;
  				for(long long j = 0; j < n; j++)//rows
  				{
  					if (!vis[j][ command[i][1]-1 ] )
  					{
  						color[j][ command[i][1]-1 ] =  command[i][2];
  						num++;
  						donerow[i]++;
  						vis[j][ command[i][1]-1 ] = 1;
  					}
  				}
  			}

  	}

  for(long long i = 0; i < n; i++){
  	for(long long j = 0; j < m; j++)
  		cout << color[i][j] <<" ";

  	cout << endl;

  }

  return 0;
}


#include <iostream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

using namespace std;
int color[5010][5010];
int vis[5010][5010];
long command[100010][3];
long long donerow[5010]={0};
long long donecol[5010]={0};

int main()
{
  long long n, m, k;
  long  long type, r, c,a;
  cin >> n >> m >> k;
  long long num=0, rr = 0, cc = 0, thre = n*m;
  memset(vis, 0, sizeof(vis) );
  memset(color, 0, sizeof(color) );

  for(long  long i = 0; i < k; i++)
  {
  	cin >> command[i][0] >> command[i][1] >> command[i][2];
  }

  	for(long  long i = k-1; i >=0 && rr < n && cc < m  && num < thre; i--)
  	{

  		if (command[i][0] == 1)
  		{
  			if (donecol[i])
  				continue;
  			for(long long j = 0; j < m; j++)//cols
  			{
  				if (!vis[ command[i][1]-1 ][j])
  				{
  					color[ command[i][1]-1 ][j] =  command[i][2];
  					num++;
  					donecol[i]=1;
  					vis[ command[i][1]-1 ][j] = 1;
  				}
  			}

  		}

  		else {
  				if (donerow[i])
  					continue;
  				for(long long j = 0; j < n; j++)//rows
  				{
  					if (!vis[j][ command[i][1]-1 ] )
  					{
  						color[j][ command[i][1]-1 ] =  command[i][2];
  						num++;
  						donerow[i] = 1;
  						vis[j][ command[i][1]-1 ] = 1;
  					}
  				}
  			}

  	}

  for(long long i = 0; i < n; i++){
  	for(long long j = 0; j < m; j++)
  		cout << color[i][j] <<" ";

  	cout << endl;

  }

  return 0;
}


#include <iostream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

using namespace std;
int color[5001][5001]={0};
int vis[5001][5001]={0};
long command[100001][3];
long long donerow[5001]={0};
long long donecol[5001]={0};

int main()
{
  long long n, m, k;
  long  long type, r, c,a;
  cin >> n >> m >> k;
  long long num=0, thre= n*m;

  for(long  long i = 0; i < k; i++)
  {
  	cin >> command[i][0] >> command[i][1] >> command[i][2];
  }

  	for(long  long i = k-1; i >=0 && num < thre; i--)
  	{

  		if (command[i][0] == 1)
  		{
  			if (donerow[i] == m)
  				continue;
  			for(long long j = 0; j < m; j++)//cols
  			{
  				if (!vis[ command[i][1]-1 ][j])
  				{
  					color[ command[i][1]-1 ][j] =  command[i][2];
  					num++;
  					donerow[i]++;
  					vis[ command[i][1]-1 ][j] = 1;
  				}
  			}

  		}

  		else {
  				if (donecol[i] == m)
  					continue;
  				for(long long j = 0; j < n; j++)//rows
  				{
  					if (!vis[j][ command[i][1]-1 ] )
  					{
  						color[j][ command[i][1]-1 ] =  command[i][2];
  						num++;
  						donecol[i]++;
  						vis[j][ command[i][1]-1 ] = 1;
  					}
  				}
  			}

  	}

  for(long long i = 0; i < n; i++){
  	for(long long j = 0; j < m; j++)
  		cout << color[i][j] <<" ";

  	cout << endl;

  }

  return 0;
}


#include <iostream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

using namespace std;
int color[5001][5001]={0};
int main()
{
  long long n, m, k;
  long long type, r, c,a;
  cin >> n >> m >> k;

  for(long long i = 0; i < k; i++)
  {
  	cin >> type;
  	if (type == 1)
  	{
  		cin >> r >> a;
  		for(long long j = 0; j < m; j++)//cols
  			color[r-1][j] =  a;

  	}

  	else {
  			cin >> c >> a;
  			for(long long j = 0; j < n; j++)//rows
  				color[j][c-1] =  a;
  		}

  }

  for(long long i = 0; i < n; i++){
  	for(long long j = 0; j < m; j++)
  		cout << color[i][j] <<" ";

  	cout << endl;

  }

  return 0;
}


#include <iostream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

using namespace std;
int color[5001][5001]={0};
int vis[5001][5001]={0};
int command[100001][3];
int main()
{
  long long n, m, k;
  long  long type, r, c,a;
  cin >> n >> m >> k;
  long long num=0, thre= n*m;

  for(long  long i = 0; i < k; i++)
  {
  	cin >> command[i][0] >> command[i][1] >> command[i][2];
  }

  	for(long  long i = k-1; i >=0 && num < thre; i--)
  	{

  		if (command[i][0] == 1)
  		{

  			for(long long j = 0; j < m; j++)//cols
  			{
  				if (!vis[ command[i][1]-1 ][j])
  				{
  					color[ command[i][1]-1 ][j] =  command[i][2];
  					num++;
  					vis[ command[i][1]-1 ][j] = 1;
  				}
  			}

  		}

  		else {
  				for(long long j = 0; j < n; j++)//rows
  				{
  					if (!vis[j][ command[i][1]-1 ] )
  					{
  						color[j][ command[i][1]-1 ] =  command[i][2];
  						num++;
  						vis[j][ command[i][1]-1 ] = 1;
  					}
  				}
  			}

  	}

  for(long long i = 0; i < n; i++){
  	for(long long j = 0; j < m; j++)
  		cout << color[i][j] <<" ";

  	cout << endl;

  }

  return 0;
}


#include <iostream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

using namespace std;
int color[5001][5001]={0};
int vis[5001][5001]={0};
int command[100001][3];
int main()
{
  long n, m, k;
  long type, r, c,a;
  cin >> n >> m >> k;
  long long num=0, thre= n*m;

  for(int i = 0; i < k; i++)
  {
  	cin >> command[i][0] >> command[i][1] >> command[i][2];
  }

  	for(int i = k-1; i >=0 && num < thre; i--)
  	{

  		if (command[i][0] == 1)
  		{

  			for(int j = 0; j < m; j++)//cols
  			{
  				if (!vis[ command[i][1]-1 ][j])
  				{
  					color[ command[i][1]-1 ][j] =  command[i][2];
  					num++;
  					vis[ command[i][1]-1 ][j] = 1;
  				}
  			}

  		}

  		else {
  				for(int j = 0; j < n; j++)//rows
  				{
  					if (!vis[j][ command[i][1]-1 ] )
  					{
  						color[j][ command[i][1]-1 ] =  command[i][2];
  						num++;
  						vis[j][ command[i][1]-1 ] = 1;
  					}
  				}
  			}

  	}

  for(int i = 0; i < n; i++){
  	for(int j = 0; j < m; j++)
  		cout << color[i][j] <<" ";

  	cout << endl;

  }

  return 0;
}


//ITNOG
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5+10;
#define ll long long
const ll MOD =1e9 + 7;
const ll INF = 1e9+10;
int main()
{
	int n ,m,k,no,r;
	ll a;
	cin >> n >> m >> k;
	ll ans[n][m];
	for(int i=0; i<n;i ++ )
		for(int j  = 0 ; j < m; j ++ )
			ans[i][j] = 0;
	for(int i= 0;i<k; i ++ )
	{
		cin >> no>>r >>a;
		r--;
		if ( no == 1 )
			for(int j=0;j<m;j++)
				ans[r][j] = a;
		else
			for(int j=0;j<n;j++)
				ans[j][r] = a;
	}
	for(int i=0; i<n;i ++ )
	{
		for(int j  = 0 ; j < m; j ++ )
			cout<<ans[i][j]<<" ";
		cout<<endl;
	}
}


//ITNOG
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5+10;
#define ll long long
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
const long long MOD =1e9 + 7;
const long long INF = 1e9+10;
int main()
{
	read_fast;
	ll r[maxN][2];
	ll c[maxN][2];
	int  s ,n ,m , k ,t;
	ll co;
	cin >> n >> m >> k;
	for(int i= 0 ; i < n; i ++ )
		r[i][1] = -1;
	for(int i= 0 ; i <m; i ++ )
		c[i][1] = -1;
	for(int  i= 0; i <k; i ++ )
	{
		cin >> t >>s >> co;
		s--;
		if ( t ==1 )
			r[s][0] = co , r[s][1] = i;
		else
			c[s][0] = co , c[s][1] = i;
	}
	for(int i = 0 ; i < n; i ++ )
	{
		for(int j = 0; j < m; j ++)
		{
			if ( r[i][1] > c[j][1]  )
				cout<<r[i][0]<<" ";
			else
				cout<<c[j][0]<< " ";
		}
		cout<<endl;
	}
}


//ITNOG
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5+10;
#define ll long long
const ll MOD =1e9 + 7;
const ll INF = 1e9+10;
int n ,m,k,no,r;
ll a;
vector<vector<ll> > ans;
int main()
{
	cin >> n >> m >> k;
	ans.resize(n);
	for(int i=0 ; i <n; i ++ )
		ans[i].resize(m);
	for(int i= 0;i<k; i ++ )
	{
		cin >> no>>r>>a;
		r--;
		if ( no == 1 )
			for(int j=0;j<m;j++)
				ans[r][j] = a;
		else
			for(int j=0;j<n;j++)
				ans[j][r] = a;
	}
	for(int i=0; i<n;i ++ )
	{
		for(int j  = 0 ; j < m; j ++ )
			cout<<ans[i][j]<<" ";
		cout<<endl;
	}
}


//ITNOG
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5+10;
#define ll long long
const ll MOD =1e9 + 7;
const ll INF = 1e9+10;
int n ,m,k,no,r;
ll a;
vector<ll> ans[maxN];
int main()
{
	cin >> n >> m >> k;
	for(int i = 0 ; i < n; i ++ )
		ans[i].resize(m);
	for(int i= 0;i<k; i ++ )
	{
		cin >> no>>r>>a;
		r--;
		if ( no == 1 )
			for(int j=0;j<m;j++)
				ans[r][j] = a;
		else
			for(int j=0;j<n;j++)
				ans[j][r] = a;
	}
	for(int i=0; i<n;i ++ )
	{
		for(int j  = 0 ; j < m; j ++ )
			cout<<ans[i][j]<<" ";
		cout<<endl;
	}
}


//ITNOG
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5+10;
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
const long long MOD =1e9 + 7;
const long long INF = 1e9+10;
int main()
{
	read_fast;
	int n ,m,k;
	long long a , nor , r;
//	cin >> n >> m >> k;
	scanf("%d", &n );
	scanf("%d", &m );
	scanf("%d", &k );
	long long ans[n][m];
	for(int i=0; i<n;i ++ )
		for(int j  = 0 ; j < m; j ++ )
			ans[i][j] = 0;
	for(int i= 0;i<k; i ++ )
	{
//		cin >> no>>r >>a;
		scanf("%Ld",&nor);
		scanf("%Ld", &r);
		scanf("%Ld" ,&a);
		r--;
		if ( nor == 1 )
			for(int j=0;j<m;j++)
				ans[r][j] = a;
		else
			for(int j=0;j<n;j++)
				ans[j][r] = a;
	}
	for(int i=0; i<n;i ++ )
	{
		for(int j  = 0 ; j < m; j ++ )
			printf("%Ld" ,ans[i][j] ) , printf(" " );
		//	cout<<ans[i][j]<<" ";
		printf("\n");
	//	cout<<endl;
	}
}


//ITNOG
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5+10;
#define ll long long
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
const ll MOD =1e9 + 7;
const ll INF = 1e9+10;
int main()
{
	read_fast;
	int n ,m,k,no,r;
	ll a;
	cin >> n >> m >> k;
	ll ans[n][m];
	for(int i=0; i<n;i ++ )
		for(int j  = 0 ; j < m; j ++ )
			ans[i][j] = 0;
	for(int i= 0;i<k; i ++ )
	{
		cin >> no>>r >>a;
		r--;
		if ( no == 1 )
			for(int j=0;j<m;j++)
				ans[r][j] = a;
		else
			for(int j=0;j<n;j++)
				ans[j][r] = a;
	}
	for(int i=0; i<n;i ++ )
	{
		for(int j  = 0 ; j < m; j ++ )
			cout<<ans[i][j]<<" ";
		cout<<endl;
	}
}


#include<iostream>
#include<conio.h>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#include<conio.h>
#include<cmath>
#include<string>
#include<stdio.h>
#include<algorithm>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef float fl;
typedef pair<ll, ll> pii;
typedef vector <int> vint;
typedef vector < pii > pvint;
typedef vector <bool> bvint;
typedef vector <vint> vvint;
const int inf=1000*1000*1000+9;
pii setir[5009];
pii sutun[5009];
int main()
{
	ll n,k,m;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=k;i++){
		ll san, q, r;
		scanf("%I64d%I64d%I64d",&san,&q,&r);
		if(san==2){
			setir[q]={r,i};
		}
		else{
			sutun[q]={r,i};
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(sutun[i].ff==0 && setir[j].ff==0)printf("%d ",0);
			else{
				if(sutun[i].ff==0) printf("%I64d ",setir[j].ff);
				else if(setir[j].ff==0) printf("%I64d ",sutun[i].ff);
				else{
					if(sutun[i].ss<setir[j].ss) printf("%I64d ",setir[j].ff);else printf("%I64d ",sutun[i].ff);
				}
			}
		}printf("\n");
	}
	return 0;
}


#include<iostream>
#include<conio.h>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#include<conio.h>
#include<cmath>
#include<string>
#include<stdio.h>
#include<algorithm>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef float fl;
typedef pair<int, int> pii;
typedef vector <int> vint;
typedef vector < pii > pvint;
typedef vector <bool> bvint;
typedef vector <vint> vvint;
const int inf=1000*1000*1000+9;
int n,m,k;
int a[5009][5009];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	while(k--){
		int san,i,f;
		scanf("%d%d%d",&san,&i,&f);
		if(san==1) for(int j=1;j<=m;j++)a[i][j]=f;
		else for(int j=1;j<=n;j++)a[j][i]=f;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<a[i][j]<<" ";
		}cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<conio.h>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#include<conio.h>
#include<cmath>
#include<string>
#include<stdio.h>
#include<algorithm>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef float fl;
typedef pair<ll, ll> pii;
typedef vector <int> vint;
typedef vector < pii > pvint;
typedef vector <bool> bvint;
typedef vector <vint> vvint;
const int inf=1000*1000*1000+9;
pii setir[5009];
pii sutun[5009];
int main()
{
	ll n,k,m;
	cin>>n>>m>>k;
	for(int i=1;i<=k;i++){
		ll san, q, r;
		cin>>san>>q>>r;
		//scanf("%I64d%I64d%I64d",&san,&q,&r);
		if(san==2){
			setir[q]={r,i};
		}
		else{
			sutun[q]={r,i};
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(sutun[i].ff==0 && setir[j].ff==0)printf("%d ",0);
			else{
				if(sutun[i].ff==0) printf("%I64d ",setir[j].ff);
				else if(setir[j].ff==0) printf("%I64d ",sutun[i].ff);
				else{
					if(sutun[i].ss<setir[j].ss) printf("%I64d ",setir[j].ff);else printf("%I64d ",sutun[i].ff);
				}
			}
		}printf("\n");
	}
	return 0;
}


#include<iostream>
#include<conio.h>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#include<conio.h>
#include<cmath>
#include<string>
#include<stdio.h>
#include<algorithm>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef float fl;
typedef pair<int, int> pii;
typedef vector <int> vint;
typedef vector < pii > pvint;
typedef vector <bool> bvint;
typedef vector <vint> vvint;
const int inf=1000*1000*1000+9;
int n,m,k;
int a[5009][5009];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	while(k--){
		int san,i,f;
		scanf("%d%d%d",&san,&i,&f);
		if(san==1) for(int j=1;j<=m;j++)a[i][j]=f;
		else for(int j=1;j<=n;j++)a[j][i]=f;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			printf("%d ",a[i][j]);
		}printf("\n");
	}
	return 0;
}


#include<iostream>
#include<conio.h>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#include<conio.h>
#include<cmath>
#include<string>
#include<stdio.h>
#include<algorithm>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef float fl;
typedef pair<ll, ll> pii;
typedef vector <int> vint;
typedef vector < pii > pvint;
typedef vector <bool> bvint;
typedef vector <vint> vvint;
const int inf=1000*1000*1000+9;
int n,m,k;
ll a[5009][5009];
pair< int, pii >p[1000009];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	/*while(k--){
		ll san,i,f;
		scanf("%I64d%I64d%I64d",&san,&i,&f);
		if(san==1) for(int j=1;j<=m;j++)a[i][j]=f;
		else for(int j=1;j<=n;j++)a[j][i]=f;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			printf("%I64d ",a[i][j]);
		}printf("\n");
	}*/
	vint setir(n+1,1),sutun(m+1,1);
	for(int i=1;i<=k;i++)cin>>p[i].ff>>p[i].ss.ff>>p[i].ss.ss;
	return 0;
}


#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<fstream>
#define pf printf
#define sf scanf
#define mod 1000000007
#define inf 1<<30
#define eps 1e-9
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define read(n) sf("%I64d",&n)
#define pi acos(-1)
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, n) for(int i = 1; i <= n; ++i)
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
int dxx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dyy[] = {0, +1, 0, -1, +1, -1, +1, -1};
///__gcd(x,y)  gcd__function
///vector < vector <int> > a1(5, vector <int> (5,1));***2-d vector with value 1 in each element
using namespace std;
set <int>::iterator it;
typedef long long ll;
ll arr[5001][5001];
main()
{
                                                         ///memset(ar,0,sizeof(ar));
                                                        ///freopen("input.txt","r",stdin);
                                                       ///freopen("output.txt","w",stdout);
                                                      ///ios_base::sync_with_stdio(0);  cin.tie(NULL);
    ///**************************************************************************************************************************************************

    ll n,n1,n2,m,m1,m2,a,b,c,i,j,k,l,l1,l2,t,t1,t2,s,s1,s2,cnt=0,cnt1,cnt2,temp;
    ll r,x,y;
    sf("%I64d %I64d %I64d",&r,&c,&k);
    //memset(arr,0,sizeof(arr));
    for(i=0;i<k;i++){
        sf("%I64d %I64d %I64d",&a,&b,&t);
        if(a==1){
                b--;
            for(x=0;x<c;x++){
                arr[b][x]=t;
            }
        }
        else if(a==2){
            b--;
            for(y=0;y<r;y++){
                arr[y][b]=t;
            }
        }
    }
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            pf("%I64d ",arr[i][j]);
        }
        pf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<fstream>
#define pf printf
#define sf scanf
#define mod 1000000007
#define inf 1<<30
#define eps 1e-9
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define read(n) sf("%I64d",&n)
#define pi acos(-1)
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, n) for(int i = 1; i <= n; ++i)
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
int dxx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dyy[] = {0, +1, 0, -1, +1, -1, +1, -1};
///__gcd(x,y)  gcd__function
///vector < vector <int> > a1(5, vector <int> (5,1));***2-d vector with value 1 in each element
using namespace std;
set <int>::iterator it;
typedef long long ll;
ll arr[5005][5005];
main()
{
                                                         ///memset(ar,0,sizeof(ar));
                                                        ///freopen("input.txt","r",stdin);
                                                       ///freopen("output.txt","w",stdout);
                                                      ///ios_base::sync_with_stdio(0);  cin.tie(NULL);
    ///**************************************************************************************************************************************************

    ll n,n1,n2,m,m1,m2,a,b,c,i,j,k,l,l1,l2,t,t1,t2,s,s1,s2,cnt=0,cnt1,cnt2,temp;
    ll r,x,y;
    sf("%I64d %I64d %I64d",&r,&c,&k);
    memset(arr,0,sizeof(arr));
    for(i=0;i<k;i++){
        sf("%I64d %I64d %I64d",&a,&b,&t);
        if(a==1){
                b--;
            for(x=0;x<c;x++){
                arr[b][x]=t;
            }
        }
        else if(a==2){
            b--;
            for(y=0;y<r;y++){
                arr[y][b]=t;
            }
        }
    }
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            pf("%I64d ",arr[i][j]);
        }
        pf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<fstream>
#define pf printf
#define sf scanf
#define mod 1000000007
#define inf 1<<30
#define eps 1e-9
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define read(n) sf("%I64d",&n)
#define pi acos(-1)
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, n) for(int i = 1; i <= n; ++i)
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
int dxx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dyy[] = {0, +1, 0, -1, +1, -1, +1, -1};
///__gcd(x,y)  gcd__function
///vector < vector <int> > a1(5, vector <int> (5,1));***2-d vector with value 1 in each element
using namespace std;
set <int>::iterator it;
typedef long long ll;
main()
{
                                                         ///memset(ar,0,sizeof(ar));
                                                        ///freopen("input.txt","r",stdin);
                                                       ///freopen("output.txt","w",stdout);
                                                      ///ios_base::sync_with_stdio(0);  cin.tie(NULL);
    ///**************************************************************************************************************************************************

    ll n,n1,n2,m,m1,m2,a,b,c,i,j,k,l,l1,l2,t,t1,t2,s,s1,s2,cnt=0,cnt1,cnt2,temp;
    ll r,x,y;
    sf("%I64d %I64d %I64d",&r,&c,&k);
    ll arr[r][c];
    memset(arr,0,sizeof(arr));
    for(i=0;i<k;i++){
        sf("%I64d %I64d %I64d",&a,&b,&t);
        if(a==1){
                b--;
            for(x=0;x<c;x++){
                arr[b][x]=t;
            }
        }
        else if(a==2){
            b--;
            for(y=0;y<r;y++){
                arr[y][b]=t;
            }
        }
    }
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            pf("%I64d ",arr[i][j]);
        }
        pf("\n");
    }
    return 0;
}


//
// Created by 王若璇 on 16/3/4.
//
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <stack>
using namespace std;
const int max_size = 5050;
int mapp[max_size][max_size];
stack<pair<int,pair<int,int> > > st;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,k;
    while (cin>>n>>m>>k){
        memset(mapp,0, sizeof(mapp));

        int op,id,num;
        for(int i = 0;i<k;i++){
            cin>>op>>id>>num;
            st.push(make_pair(op,make_pair(id,num)));
        }
        pair<int,pair<int,int> > now;
        while (!st.empty()){
            now = st.top();
            st.pop();
            if(now.first==1){
                for(int i = 1;i<=m;i++){
                    if(!mapp[now.second.first][i]){
                        mapp[now.second.first][i] = now.second.second;
                    }
                }
            } else{
                for(int i = 1;i<=n;i++){
                    if(!mapp[i][now.second.first]){
                        mapp[i][now.second.first] = now.second.second;
                    }
                }
            }
        }
        for(int j = 1;j<=n;j++){
            for(int i = 1;i<=m;i++){
                cout<<mapp[j][i]<<" ";
            }
            cout<<"\n";
        }
    }
    return 0;
}


//
// Created by 王若璇 on 16/3/4.
//
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int max_n = 5050;
struct pp{
    int num;
    int a;
    bool operator<(const pp &p) const {
        return num<p.num;
    }
    pp(){}
    pp(int num,int a){
        this->num = num;
        this->a = a;
    }
    void clear(){
        this->num = 0;
        this->a = 0;
    }
};
pp row[max_n];
pp column[max_n];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,k;
    while (cin>>n>>m>>k){

        int op,id,num;
        for(int i = 0;i<max_n;i++){
            row[i].clear();
            column[i].clear();
        }
        for(int i = 0;i<k;i++){
            cin>>op>>id>>num;
            if(op==1){
                if(id>n){
                    continue;
                }
                row[id] = pp(i,num);
            } else{
                if(id>m){
                    continue;
                }
                column[id] = pp(i,num);
            }
        }
        for(int j = 1;j<=n;j++){
            for(int i = 1;i<=m;i++){
                if(row[j]<column[i]){
                    cout<<column[i].a<<" ";
                } else{
                    cout<<row[j].a<<" ";
                }
            }
            cout<<'\n';
        }
    }

    return 0;
}


//
// Created by 王若璇 on 16/3/4.
//
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <stack>
using namespace std;
const int max_size = 5050;
int mapp[max_size][max_size];
stack<pair<int,pair<int,int> > > st;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,k;
    while (cin>>n>>m>>k){
        memset(mapp,0, sizeof(mapp));

        int op,id,num;
        for(int i = 0;i<n;i++){
            cin>>op>>id>>num;
            st.push(make_pair(op,make_pair(id,num)));
        }
        pair<int,pair<int,int> > now;
        while (!st.empty()){
            now = st.top();
            st.pop();
            if(now.first==1){
                for(int i = 1;i<=m;i++){
                    if(!mapp[now.second.first][i]){
                        mapp[now.second.first][i] = now.second.second;
                    }
                }
            } else{
                for(int i = 1;i<=n;i++){
                    if(!mapp[i][now.second.first]){
                        mapp[i][now.second.first] = now.second.second;
                    }
                }
            }
        }
        for(int j = 1;j<=n;j++){
            for(int i = 1;i<=m;i++){
                cout<<mapp[j][i]<<" ";
            }
            cout<<"\n";
        }
    }
    return 0;
}


//
// Created by 王若璇 on 16/3/4.
//
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int max_n = 5050;
int mapp[max_n][max_n];
struct pp{
    int num;
    int a;
    bool operator<(const pp &p) const {
        return num<p.num;
    }
    pp(){}
    pp(int num,int a){
        this->num = num;
        this->a = a;
    }
    void clear(){
        this->num = 0;
        this->a = 0;
    }
};
pp row[max_n];
pp column[max_n];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,k;
    while (cin>>n>>m>>k){
        memset(mapp,0, sizeof(mapp));

        int op,id,num;
        for(int i = 0;i<max_n;i++){
            row[i].clear();
            column[i].clear();
        }
        for(int i = 0;i<k;i++){
            cin>>op>>id>>num;
            if(op==1){
                row[id] = pp(i,num);
            } else{
                column[id] = pp(i,num);
            }
        }
        for(int j = 1;j<=n;j++){
            for(int i = 1;i<=m;i++){
                if(row[j]<column[i]){
                    cout<<column[i].a<<" ";
                } else{
                    cout<<row[j].a<<" ";
                }
            }
            cout<<'\n';
        }
    }

    return 0;
}


//
// Created by 王若璇 on 16/3/4.
//
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int max_n = 5050;
struct pp{
    int num;
    int a;
    bool operator<(const pp &p) const {
        return num<p.num;
    }
    pp(){}
    pp(int num,int a){
        this->num = num;
        this->a = a;
    }
    void clear(){
        this->num = 0;
        this->a = 0;
    }
};
pp row[max_n];
pp column[max_n];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,k;
    while (cin>>n>>m>>k){

        int op,id,num;
        for(int i = 0;i<max_n;i++){
            row[i].clear();
            column[i].clear();
        }
        for(int i = 1;i<=k;i++){
            cin>>op>>id>>num;
            if(op==1){
                if(id>n){
                    continue;
                }
                row[id] = pp(i,num);
            } else{
                if(id>m){
                    continue;
                }
                column[id] = pp(i,num);
            }
        }
        for(int j = 1;j<=n;j++){
            for(int i = 1;i<=m;i++){
                if(row[j]<column[i]){
                    cout<<column[i].a<<" ";
                } else{
                    cout<<row[j].a<<" ";
                }
            }
            cout<<'\n';
        }
    }

    return 0;
}


#include<iostream>
#include<string.h>
#include<algorithm>
#define max(a,b) (a > b ? a : b)
#define WHILE(x) while(x--)
#define FOR(x,y,z) for(int x = y; x < z; x++)
#define N 5000 + 10
using namespace std;

int pictrue[N][N];
int row[N];
int column[N];
int main()
{
	int n,m,i,j,k,a,b;
	cin>>n>>m>>k;

	memset(pictrue,0,sizeof(pictrue));

	while(k--){
		cin>>j>>a>>b;
		switch(j){
			case 1: for(i = 0; i < m; i++)
						pictrue[a-1][i] = b;
					break;
			case 2: for(i = 0; i < n; i++)
						pictrue[i][a-1] = b;
					break;
			default: break;
		}
	}

	FOR(i,0,n)
	{
		FOR(j,0,m)
		{
			printf("%d",pictrue[i][j]);
			if(j != m-1)
				printf(" ");
		}
		cout<<endl;
	}
return 0;
}


#include<iostream>
#include<string.h>
#include<algorithm>
#define max(a,b) (a > b ? a : b)
#define WHILE(x) while(x--)
#define FOR(x,y,z) for(int x = y; x < z; x++)
#define N 5000 + 10
using namespace std;

long long pictrue[N][N];
long long row[N];
long long column[N];
int main()
{
	long long n,m,i,j,k,a,b;
	cin>>n>>m>>k;

	memset(pictrue,0,sizeof(pictrue));
	memset(row,0,sizeof(row));
	memset(column,0,sizeof(column));
	while(k--){
		cin>>j>>a>>b;
		switch(j){
			case 1:
					if(pictrue[a-1][0] == b && row[a-1] != 0)
						break;
					for(i = 0, row[a-1] = b; i < m; i++)
						pictrue[a-1][i] = b;
					break;
			case 2:
					if(pictrue[0][a-1] == b && column[a-1] != 0)
						break;
					for(i = 0, column[a-1] = b; i < n; i++)
						pictrue[i][a-1] = b;
					break;
			default: break;
		}
	}

	FOR(i,0,n)
	{
		FOR(j,0,m)
		{
			printf("%lld",pictrue[i][j]);
			if(j != m-1)
				printf(" ");
		}
		cout<<endl;
	}
return 0;
}


#include<iostream>
#include<string.h>
#include<algorithm>
#define max(a,b) (a > b ? a : b)
#define WHILE(x) while(x--)
#define FOR(x,y,z) for(int x = y; x < z; x++)
#define N 5000
using namespace std;

int pictrue[N][N];
int main()
{
	int n,m,i,j,k,a,b;
	cin>>n>>m>>k;

	memset(pictrue,0,sizeof(pictrue));

	while(k--){
		cin>>j>>a>>b;
		switch(j){
			case 1: for(i = 0; i < m; i++)
						pictrue[a-1][i] = b;
					break;
			case 2: for(i = 0; i < n; i++)
						pictrue[i][a-1] = b;
					break;
			default: break;
		}
	}

	FOR(i,0,n)
	{
		FOR(j,0,m)
		{
			printf("%d",pictrue[i][j]);
			if(j != m-1)
				printf(" ");
		}
		cout<<endl;
	}
return 0;
}


#include<iostream>
#include<string.h>
#include<algorithm>
#define max(a,b) (a > b ? a : b)
#define WHILE(x) while(x--)
#define FOR(x,y,z) for(int x = y; x < z; x++)
#define N 5000 + 10
using namespace std;

int pictrue[N][N];
int row[N];
int column[N];
int main()
{
	int n,m,i,j,k,a,b;
	cin>>n>>m>>k;

	memset(pictrue,0,sizeof(pictrue));
	memset(row,0,sizeof(row));
	memset(column,0,sizeof(column));
	while(k--){
		cin>>j>>a>>b;
		switch(j){
			case 1:
					if(pictrue[a-1][0] == b && row[a-1] != 0)
						break;
					for(i = 0, row[a-1] = b; i < m; i++)
						pictrue[a-1][i] = b;
					break;
			case 2:
					if(pictrue[0][a-1] == b && column[a-1] != 0)
						break;
					for(i = 0, column[a-1] = b; i < n; i++)
						pictrue[i][a-1] = b;
					break;
			default: break;
		}
	}

	FOR(i,0,n)
	{
		FOR(j,0,m)
		{
			printf("%d",pictrue[i][j]);
			if(j != m-1)
				printf(" ");
		}
		cout<<endl;
	}
return 0;
}


#include<iostream>
#include<string.h>
#include<algorithm>
#define max(a,b) (a > b ? a : b)
#define WHILE(x) while(x--)
#define FOR(x,y,z) for(int x = y; x < z; x++)
#define N 5000
using namespace std;

int pictrue[N][N];
int main()
{
	int n,m,i,j,k,a,b;
	cin>>n>>m>>k;

	FOR(i,0,n)
		FOR(j,0,m)
			pictrue[i][j] = 0;

	while(k--){
		cin>>j>>a>>b;
		switch(j){
			case 1: for(i = 0; i < m; i++)
						pictrue[a-1][i] = b;
					break;
			case 2: for(i = 0; i < n; i++)
						pictrue[i][a-1] = b;
					break;
			default: break;
		}
	}

	FOR(i,0,n)
	{
		FOR(j,0,m)
		{
			printf("%d",pictrue[i][j]);
			if(j != m-1)
				printf(" ");
		}
		cout<<endl;
	}
return 0;
}


#include <cstdio>
#define N 5000 + 10
#define max(a,b) (a > b ? a : b)
int n, m, k,t, p,l[N], c[N], x[N];
int main() {
    scanf("%d %d %d", &n, &m, &k);
    x[0] = 0;
    for (int i = 1; i <= k; ++i) {
        scanf("%d %d %d", &t, &p, &x[i]);
        if (t == 1) l[--p] = i;
        else c[--p] = i;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j)
            printf("%d ", x[max(l[i], c[j])]);
        putchar('\n');
    }
    return 0;
}


#include <bits/stdc++.h>
#define s(x) scanf("%d",&x)
using namespace std;
int main()
{
    int row[5005];
    int colm[5005];
    memset(row,0,sizeof row);
    memset(colm,0,sizeof colm);
    int arr[10010];
    int t,no,col,n,m,k,i,j;
    s(n),s(m),s(k);
    for(i=1;i<=k;i++)
    {
        s(t),s(no),s(col);
        arr[i]=col;
        if(t==1)
            row[no]=i;
        else
            colm[no]=i;
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            //if(row[i]==0 && colm[j]==0)
              //  printf("0 ");
            //else if(row[i]>colm[j])
              //  printf("%d ",arr[row[i]]);
            //else
                printf("%d ",arr[max(row[i],colm[j])]);
        }
        printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    map<int,int> row;
    map<int,int> colm;
    int arr[10000][2];
    int t,no,col,n,m,k,i,j;
    cin>>n>>m>>k;
    for(i=1;i<=k;i++)
    {
        cin>>t>>no>>col;
        arr[i][1]=t;
        arr[i][0]=col;
        if(t==1)
            row[no]=i;
        else
            colm[no]=i;
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(row[i]==0 && colm[j]==0)
                cout<<"0 ";
            else if(row[i]>colm[j])
                cout<<arr[row[i]][0]<<" ";
            else
                cout<<arr[colm[j]][0]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define s(x) scanf("%ld",&x)
using namespace std;
int main()
{
    long int row[5005];
    long int colm[5005];
    long int arr[10010];
    memset(row,0,sizeof row);
    memset(colm,0,sizeof colm);
    memset(arr,0,sizeof arr);
    long int t,no,col,n,m,k,i,j;
    s(n),s(m),s(k);
    for(i=1;i<=k;i++)
    {
        s(t),s(no),s(col);
        arr[i]=col;
        if(t==1)
            row[no]=i;
        else
            colm[no]=i;
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            //if(row[i]==0 && colm[j]==0)
              //  printf("0 ");
            //else if(row[i]>colm[j])
              //  printf("%d ",arr[row[i]]);
            //else
                printf("%d ",arr[max(row[i],colm[j])]);
        }
        printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define s(x) scanf("%ld",&x)
using namespace std;
int main()
{
    long int row[5005];
    long int colm[5005];
    long int arr[10010];
    memset(row,0,sizeof row);
    memset(colm,0,sizeof colm);
    memset(arr,0,sizeof arr);
    long int t,no,col,n,m,k,i,j;
    s(n),s(m),s(k);
    for(i=1;i<=k;i++)
    {
        s(t),s(no),s(col);
        arr[i]=col;
        if(t==1)
            row[no-1]=i;
        else
            colm[no-1]=i;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            printf("%ld ",arr[max(row[i],colm[j])]);
        }
        printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	long int n,i,j,k,m,x,b;
	cin>>n>>m>>k;
	long int r[n]={0},c[m]={0},s[k+1]={0};
	for(i=1;i<=k;i++)
	{
		cin>>x>>b>>s[i];
		if(x==1)
			r[b-1]=i;
		else
			c[b-1]=i;
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			cout<<s[max(r[i],c[j])]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define s(x) scanf("%d",&x)
using namespace std;
int main()
{
    int row[5005];
    int colm[5005];
    memset(row,0,sizeof row);
    memset(colm,0,sizeof colm);
    int arr[10010];
    int t,no,col,n,m,k,i,j;
    s(n),s(m),s(k);
    for(i=1;i<=k;i++)
    {
        s(t),s(no),s(col);
        arr[i]=col;
        if(t==1)
            row[no]=i;
        else
            colm[no]=i;
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(row[i]==0 && colm[j]==0)
                printf("0 ");
            else if(row[i]>colm[j])
                printf("%d ",arr[row[i]]);
            else
                printf("%d ",arr[colm[j]]);
        }
        printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define s(x) scanf("%d",&x)
using namespace std;
int main()
{
    int row[5005];
    int colm[5005];
    int arr[10010];
    memset(row,0,sizeof row);
    memset(colm,0,sizeof colm);
    memset(arr,0,sizeof arr);
    int t,no,col,n,m,k,i,j;
    s(n),s(m),s(k);
    for(i=1;i<=k;i++)
    {
        s(t),s(no),s(col);
        arr[i]=col;
        if(t==1)
            row[no]=i;
        else
            colm[no]=i;
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            //if(row[i]==0 && colm[j]==0)
              //  printf("0 ");
            //else if(row[i]>colm[j])
              //  printf("%d ",arr[row[i]]);
            //else
                printf("%d ",arr[max(row[i],colm[j])]);
        }
        printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define s(x) scanf("%ld",&x)
using namespace std;
int main()
{
    long int row[5005];
    long int colm[5005];
    long int arr[10010];
    memset(row,0,sizeof row);
    memset(colm,0,sizeof colm);
    memset(arr,0,sizeof arr);
    int t,no,col,n,m,k,i,j;
    s(n),s(m),s(k);
    for(i=1;i<=k;i++)
    {
        s(t),s(no),s(col);
        arr[i]=col;
        if(t==1)
            row[no-1]=i;
        else
            colm[no-1]=i;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            printf("%d ",arr[max(row[i],colm[j])]);
        }
        printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define s(x) scanf("%d",&x)
using namespace std;
int main()
{
    int row[5005];
    int colm[5005];
    int arr[10010];
    memset(row,0,sizeof row);
    memset(colm,0,sizeof colm);
    memset(arr,0,sizeof arr);
    int t,no,col,n,m,k,i,j;
    s(n),s(m),s(k);
    for(i=1;i<=k;i++)
    {
        s(t),s(no),s(col);
        arr[i]=col;
        if(t==1)
            row[no-1]=i;
        else
            colm[no-1]=i;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            printf("%d ",arr[max(row[i],colm[j])]);
        }
        printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    map<int,int> row;
    map<int,int> colm;
    int arr[100010][2];
    int t,no,col,n,m,k,i,j;
    cin>>n>>m>>k;
    for(i=1;i<=k;i++)
    {
        cin>>t>>no>>col;
        arr[i][1]=t;
        arr[i][0]=col;
        if(t==1)
            row[no]=i;
        else
            colm[no]=i;
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(row[i]==0 && colm[j]==0)
                cout<<"0 ";
            else if(row[i]>colm[j])
                cout<<arr[row[i]][0]<<" ";
            else
                cout<<arr[colm[j]][0]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define xx first
#define yy second
#define mas it->yy
typedef long long ll;
typedef pair<int, int> pii;

int n, m, k, type, x, y;
int matr[5007][5007];
int main()
{
    scanf("%d %d %d", &n, &m, &k);
    for(int t = 0; t < k; ++t)
    {
        scanf("%d %d %d", &type, &x, &y);
        x--;
        if(type == 1)
        {
            for(int i = 0; i < m; ++i)
                matr[x][i] = y;
        }
        else
            for(int i = 0; i < n; ++i)
                matr[i][x] = y;
        /*
        for(int i = 0; i < n; ++i)
        {
            for(int j = 0; j < m; ++j)
                printf("%d ", matr[i][j]);
            printf("\n");
        }
        printf("\n\n\n\n");
        */
    }
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
            printf("%d ", matr[i][j]);
        printf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define xx first
#define yy second
#define mas it->yy
typedef long long ll;
typedef pair<int, int> pii;

int n, m, k, type, x, y;
//int matr[5007][5007];
int main()
{
    scanf("%d %d %d", &n, &m, &k);
    vector<pii> a(n, {0, -1}), b(m, {0, -1});
    for(int t = 0; t < k; ++t)
    {
        scanf("%d %d %d", &type, &x, &y);
        x--;
        if (type == 1)
            a[x] = {y, t};
        else
            b[x] = {y, t};
        /*
        for(int i = 0; i < n; ++i)
        {
            for(int j = 0; j < m; ++j)
                if (a[i].yy > b[j].yy)
                    printf("%d ", a[i].xx);
                else
                    printf("%d ", b[j].xx);
            printf("\n");
        }
        printf("\n\n\n\n");
        */
    }
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
            if (a[i].yy > b[j].yy)
                printf("%d ", a[i].xx);
            else
                printf("%d ", b[j].xx);
        printf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define xx first
#define yy second
#define mas it->yy
typedef long long ll;
typedef pair<int, int> pii;

int n, m, k, type, x, y;
int matr[5001][5001];
int main()
{
    scanf("%d %d %d", &n, &m, &k);
    for(int t = 0; t < k; ++t)
    {
        scanf("%d %d %d", &type, &x, &y);
        x--;
        if(type == 1)
        {
            for(int i = 0; i < m; ++i)
                matr[x][i] = y;
        }
        else
            for(int i = 0; i < n; ++i)
                matr[i][x] = y;
    }
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
            printf("%d ", matr[i][j]);
        printf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define xx first
#define yy second
#define mas it->yy
typedef long long ll;
typedef pair<int, int> pii;

int n, m, k, type, x, y;
//int matr[5007][5007];
int main()
{
    scanf("%d %d %d", &n, &m, &k);
    vector<pii> a(n, {0, -1}), b(m, {0, -1});
    for(int t = 0; t < n; ++t)
    {
        scanf("%d %d %d", &type, &x, &y);
        x--;
        if (type == 1)
            a[x] = {y, t};
        else
            b[x] = {y, t};
    }
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
            if (a[i].yy > b[j].yy)
                printf("%d ", a[i].xx);
            else
                printf("%d ", b[j].xx);
        printf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define xx first
#define yy second
#define mas it->yy
typedef long long ll;
typedef pair<int, int> pii;

int n, m, k, type, x, y;
//int matr[5007][5007];
int main()
{
    scanf("%d %d %d", &n, &m, &k);
    int matr[n][m];
    for(int t = 0; t < k; ++t)
    {
        scanf("%d %d %d", &type, &x, &y);
        x--;
        if(type == 1)
        {
            for(int i = 0; i < m; ++i)
                matr[x][i] = y;
        }
        else
            for(int i = 0; i < n; ++i)
                matr[i][x] = y;
        /*
        for(int i = 0; i < n; ++i)
        {
            for(int j = 0; j < m; ++j)
                printf("%d ", matr[i][j]);
            printf("\n");
        }
        printf("\n\n\n\n");
        */
    }
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
            printf("%d ", matr[i][j]);
        printf("\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define xx first
#define yy second
#define mas it->yy
typedef long long ll;
typedef pair<int, int> pii;

int n, m, k, type, x, y;
//int matr[5007][5007];
int main()
{
    scanf("%d %d %d", &n, &m, &k);
    int matr[n][m];
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j)
            matr[i][j] = 0;
    for(int t = 0; t < k; ++t)
    {
        scanf("%d %d %d", &type, &x, &y);
        x--;
        if(type == 1)
        {
            for(int i = 0; i < m; ++i)
                matr[x][i] = y;
        }
        else
            for(int i = 0; i < n; ++i)
                matr[i][x] = y;
        /*
        for(int i = 0; i < n; ++i)
        {
            for(int j = 0; j < m; ++j)
                printf("%d ", matr[i][j]);
            printf("\n");
        }
        printf("\n\n\n\n");
        */
    }
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
            printf("%d ", matr[i][j]);
        printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define mp  make_pair
#define pb  push_back
#define fios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg printf("\n");
#define pp pair<ll,ll>
#define okk printf("%s\n","nabel");
#define ll long long
#define nl cout<<endl;
#define rep(i,n) for(ll i =0;i<n;++i)
#define repv(i,v,n) for(ll i =v;i<n;++i)
#define rows(arr) sizeof(arr)/sizeof(arr[0])
#define cols(arr)  sizeof(arr[0])/sizeof(arr[0][0])
using namespace std;
typedef long double ld;
int main()
{
    fios
    ll n , m , k ,x , y , z;
    while(cin >> n >> m >> k )
    {
        ll c[n][m];
        memset(c,0,sizeof c );
        for(ll g =0; g<k   ; ++g  )
        {
            cin >> x >> y >> z;
            if(x==1)
                for(ll j =0; j<m   ; ++j  )
                    c[y-1][j]=z;
            else if(x == 2)
                for(ll j =0; j<n   ; ++j  )
                    c[j][y-1]=z;
        }
        rep(i,n)
        {
            rep(j,m)
            cout<<c[i][j]<<" ";

            nl
        }

    }
    return 0;
}


#include <cstdio>
#include <algorithm>

const int N = 5000, K = (int)1e5 + 1;

int n, m, k;
int t, p;
int l[N], c[N], x[K];

int main() {
    scanf("%d%d%d", &n, &m, &k);

    x[0] = 0;

    for (int i = 1; i <= k; ++i) {
        scanf("%d%d%d", &t, &p, &x[i]);
        if (t == 1)
            l[--p] = i;
        else
            c[--p] = i;
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j)
            printf("%d ", x[std::max(l[i], c[j])]);
        putchar('\n');
    }

    return 0;
}


#include <bits/stdc++.h>
#define mp  make_pair
#define pb  push_back
#define fios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg printf("\n");
#define pp pair<ll,ll>
#define okk printf("%s\n","nabel");
#define ll long long
#define nl cout<<endl;
#define rep(i,n) for(ll i =0;i<n;++i)
#define repv(i,v,n) for(ll i =v;i<n;++i)
#define rows(arr) sizeof(arr)/sizeof(arr[0])
#define cols(arr)  sizeof(arr[0])/sizeof(arr[0][0])
using namespace std;
typedef long double ld;
int main()
{
    fios
    int n , m , k ,x , y , z;
    while(cin >> n >> m >> k )
    {
        int c[n][m];
        memset(c,0,sizeof c );
        for(int g =0; g<k   ; ++g  )
        {
            cin >> x >> y >> z;
            if(x==1)
                for(int j =0; j<m   ; ++j  )
                    c[y-1][j]=z;
            else if(x == 2)
                for(int j =0; j<n   ; ++j  )
                    c[j][y-1]=z;
        }
        rep(i,n)
        {
            rep(j,m)
            cout<<c[i][j];

            nl
        }

    }
    return 0;
}


#include <bits/stdc++.h>
#define mp  make_pair
#define pb  push_back
#define fios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg printf("\n");
#define pp pair<ll,ll>
#define okk printf("%s\n","nabel");
#define ll long long
#define nl cout<<endl;
#define rep(i,n) for(ll i =0;i<n;++i)
#define repv(i,v,n) for(ll i =v;i<n;++i)
#define rows(arr) sizeof(arr)/sizeof(arr[0])
#define cols(arr)  sizeof(arr[0])/sizeof(arr[0][0])
using namespace std;
typedef long double ld;
int main()
{
    fios
    ll  n,m,x;
    cin>>n>>m>>x;
    ll r[n][2],c[m][2];
    memset(r,0,sizeof(r));
    memset(c,0,sizeof(c));
    ll j,i;
    for(i=0; i<x; i++)
    {
        ll e,y,z;
        cin>>e>>y>>z;
        if(e==1)
        {
            r[y-1][0]=z;
            r[y-1][1]=i+1;
        }
        else if(e==2)
        {
            c[y-1][0]=z;
            c[y-1][1]=i+1;
        }
    }
    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            if(r[i][1]>c[j][1])
                cout<<r[i][0]<<" ";

            else cout<<c[j][0]<<" ";
        }
        cout<<endl;
    }
}


 #include<bits/stdc++.h>
#define P(x,y) make_pair(x,y)
using namespace std;
const int MX=(1<<20);
int Q;
pair < int , int > row[MX] , col[MX];
int n , m , cmd , x ;
int main(){
    scanf("%d %d %d",&n,&m,&Q);
    for(int j=1;j<=Q;j++){
        int tt;
        scanf("%d %d %d",&cmd,&x,&tt);
        if(cmd==1) row[x] = P(tt , j);
        else col[x] = P(tt , j);
    }
    for(int j=1;j<=n;j++){
        for(int i=1;i<=m;i++){
            if(row[j].second > col[i].second)
                printf("%d ",row[j].first);
            else printf("%d ",col[i].first);
        }
        puts("");
    }
}


#include <bits/stdc++.h>
#define mp  make_pair
#define pb  push_back
#define fios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg printf("\n");
#define pp pair<ll,ll>
#define okk printf("%s\n","nabel");
#define ll long long
#define nl cout<<endl;
#define rep(i,n) for(ll i =0;i<n;++i)
#define repv(i,v,n) for(ll i =v;i<n;++i)
#define rows(arr) sizeof(arr)/sizeof(arr[0])
#define cols(arr)  sizeof(arr[0])/sizeof(arr[0][0])
using namespace std;
typedef long double ld;
int main()
{
    fios
    int n , m , k ,x , y , z;
    while(cin >> n >> m >> k )
    {
        int c[n][m];
        memset(c,0,sizeof c );
        for(int g =0; g<k   ; ++g  )
        {
            cin >> x >> y >> z;
            if(x==1)
                for(int j =0; j<m   ; ++j  )
                    c[y-1][j]=z;
            else if(x == 2)
                for(int j =0; j<n   ; ++j  )
                    c[j][y-1]=z;
        }
        rep(i,n)
        {
            rep(j,m)
            cout<<c[i][j]<<" ";

            nl
        }

    }
    return 0;
}


#include<iostream>
using namespace std ;
int main()
{
    int row ,col ,cases ;
    cin>>row ;
    if((row>=1) and(row<=5000))
    {
    cin>>col ;
    if((col>=1) and(col<=5000) and(row*col<=100000))
    {
    int **array=new int *[row] ;
    for(int i=0;i<row;i++)
        array[i]=new int [col] ;

        for(int i=0;i<row;i++)
            for(int j=0;j<col;j++)
            array[i][j]=0 ;
        cin>>cases ;
        if((cases>=1) and(cases<=100000))
        {
        int *t=new int [3] ;
        for(int i=0;i<cases;i++)
        {
            cin>>t[0] ;
            if(t[0]==1)
            {
                cin>>t[1] ;
                if(t[1]<=row)
                {
                    int dif=t[1]-1 ;
                    cin>>t[2] ;
                    for(int z=0;z<col;z++)
                      array[dif][z]=t[2] ;
                }
            }
            else if(t[0]==2)
            {
                cin>>t[1] ;
                if(t[1]<=col){
                int dif=t[1]-1 ;
                cin>>t[2] ;
                for(int z=0;z<row;z++)
                    array[z][dif]=t[2] ;
            }
            }
            else
                return 0 ;
        }
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++)
                cout<<array[i][j]<<" " ;
            cout<<endl ;
        }
        }
        else
            return 0 ;
    }
    else
        return 0 ;
}
    else
        return 0 ;
        return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

int main()
{
    int row,col,cases ;
    cin>>row>>col>>cases ;
    int one[5000] ,two[5000];
    memset(one,0,sizeof one) ;
    memset(two,0,sizeof two) ;
    int x ,y ,new_array[row*col+1] ;
    memset(new_array,0,sizeof new_array) ;
    for(int i=1;i<=cases;++i)
    {
        cin>>x>>y>>new_array[i] ;
        if(x==1)
        {
            one[y-1]=i ;
        }
        else if(x==2)

            two[y-1]=i ;
    }
    for(int i=0;i<row;++i)
    {
        for(int j=0;j<col;++j)
        {
            cout<<new_array[max(one[i],two[j])]<<" " ;
        }
        cout<<endl ;
        }
    }


#include<bits/stdc++.h>
using namespace std ;

int main()
{
    long long row,col,cases ;
    cin>>row>>col>>cases ;
    long long one[cases] ,two[cases];
    memset(one,0,sizeof one) ;
    memset(two,0,sizeof two) ;
    long long x ,y ,new_array[row*col] ;
    memset(new_array,0,sizeof new_array) ;
    for(int i=1;i<=cases;++i)
    {
        cin>>x>>y>>new_array[i] ;
        if(x==1)
        {
            one[y-1]=i ;
        }
        else
            two[y-1]=i ;
    }
    for(int i=0;i<row;++i)
    {
        for(int j=0;j<col;++j)
        {
            cout<<new_array[max(one[i],two[j])]<<" " ;
        }
        cout<<endl ;
        }
    }


#include<iostream>
using namespace std ;
int main()
{
    int row ,col ,cases ;
    cin>>row ;
    if((row>=1) and(row<=5000))
    {
    cin>>col ;
    if((col>=1) and(col<=5000) and(row*col<=100000))
    {
    int **array=new int *[row] ;
    for(int i=0;i<row;i++)
        array[i]=new int [col] ;
        for(int i=0;i<row;i++)
            for(int j=0;j<col;j++)
            array[i][j]=0 ;
        cin>>cases ;
        if((cases>=1) and(cases<=100000))
        {
        double *t=new double [3] ;
        for(int i=0;i<cases;i++)
        {
            cin>>t[0] ;
            if(t[0]==1)
            {
                cin>>t[1] ;
                if((t[1]<=row) and(t[1]>=1))
                {
                    int dif=t[1]-1 ;
                    cin>>t[2] ;
                    if((t[2]<=1000000000) and(t[2]>=1)){
                    for(int z=0;z<col;z++)
                      array[dif][z]=t[2] ;
                    }
                    else
                        return 0 ;
                }
            }
            else if(t[0]==2)
            {
                cin>>t[1] ;
                if((t[1]<=col) and(t[1]>=1)){
                int dif=t[1]-1 ;
                cin>>t[2] ;
                if((t[2]<=1000000000) and(t[2]>=1)){
                for(int z=0;z<row;z++)
                    array[z][dif]=t[2] ;
                }
                else
                    return 0 ;
            }
                else
                    return 0 ;
            }
            else
                return 0 ;
        }
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++)
                cout<<array[i][j]<<" " ;
            cout<<endl ;
        }
        }
        else
            return 0 ;
    }
    else
        return 0 ;
}
    else
        return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

int main()
{
    int row,col,cases ;
    cin>>row>>col>>cases ;
    int one[5000] ,two[5000];
    memset(one,0,sizeof one) ;
    memset(two,0,sizeof two) ;
    int x ,y ,new_array[row*col+1] ;
    memset(new_array,0,sizeof new_array) ;
    for(int i=0;i<cases;++i)
    {
        cin>>x>>y>>new_array[i] ;
        if(x==1)
        {
            one[y-1]=i+1 ;
        }
        else if(x==2)

            two[y-1]=i+1 ;
    }
    for(int i=0;i<row;++i)
    {
        for(int j=0;j<col;++j)
        {
            cout<<new_array[max(one[i],two[j])]<<" " ;
        }
        cout<<endl ;
        }
    }


#include<bits/stdc++.h>
using namespace std ;

int main()
{
    int row,col,cases ;
    cin>>row>>col>>cases ;
    int one[cases] ,two[cases];
    memset(one,0,sizeof one) ;
    memset(two,0,sizeof two) ;
    int x ,y ,new_array[row*col] ;
    for(int i=0;i<cases;++i)
    {
        cin>>x>>y>>new_array[i] ;
        if(x==1)
        {
            one[i]=i ;
        }
        else
            two[i]=i ;
    }
    int k=0 ;
    for(int i=0;i<row;++i)
    {
        for(int j=0;j<col;++j)
        {
            cout<<new_array[max(one[i],two[j])]<<" " ;
        }
        cout<<endl ;
        }
    }


#include<iostream>
using namespace std ;
int main()
{
    int row ,col ,cases ;
    cin>>row ;
    if((row>=1) and(row<=5000))
    {
    cin>>col ;
    if((col>=1) and(col<=5000) and(row*col<=100000))
    {
    int **array=new int *[row] ;
    for(int i=0;i<row;i++){
        array[i]=new int [col] ;
        for(int j=0;j<col;j++)
            array[i][j]=0 ;}
        cin>>cases ;
        if((cases>=1) and(cases<=100000))
        {
        double *t=new double [3] ;
        for(int i=0;i<cases;i++)
        {
            cin>>t[0] ;
            if(t[0]==1)
            {
                cin>>t[1] ;
                if((t[1]<=row) and(t[1]>=1))
                {
                    int dif=t[1]-1 ;
                    cin>>t[2] ;
                    if((t[2]<=1000000000) and(t[2]>=1)){
                    for(int z=0;z<col;z++)
                      array[dif][z]=t[2] ;
                    }
                    else
                        return 0 ;
                }
            }
            else if(t[0]==2)
            {
                cin>>t[1] ;
                if((t[1]<=col) and(t[1]>=1)){
                int dif=t[1]-1 ;
                cin>>t[2] ;
                if((t[2]<=1000000000) and(t[2]>=1)){
                for(int z=0;z<row;z++)
                    array[z][dif]=t[2] ;
                }
                else
                    return 0 ;
            }
                else
                    return 0 ;
            }
            else
                return 0 ;
        }
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++)
                cout<<array[i][j]<<" " ;
            cout<<endl ;
        }
        }
        else
            return 0 ;
    }
    else
        return 0 ;
}
    else
        return 0 ;
}