#include <stdio.h>

int left(int i){
	return 2*i+1;
}

int right(int i){
	return 2*i+2;
}

void maxHeapify(int arr[], int i, int hpSz){
	int l = left(i);
	int r = right(i);

	int largest = i;
	int temp;

	if(l<=hpSz && arr[l]>arr[largest]){
		largest = l;
	}

	if(r<=hpSz && arr[r]>arr[largest]){
		largest = r;
	}

	if(largest != i){
		temp = arr[i];
		arr[i] = arr[largest];
		arr[largest] = temp;
		maxHeapify(arr, largest, hpSz);
	}
}

void buildHeap(int arr[], int hpSz){
	for(int i = hpSz; i>=0;i--){
		maxHeapify(arr,i,hpSz);
	}
}

void heapSort(int arr[], int hpSz){
	int temp;
	for(int i = hpSz;i>=1;i--){
		buildHeap(arr, hpSz);

		temp = arr[hpSz];
		arr[hpSz]= arr[0];
		arr[0] = temp;

		hpSz--;
		maxHeapify(arr,0,hpSz);
	}
}

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

	int arr[2*n];

	for(int i=0; i<2*n;i++){
		scanf("%d", &arr[i]);
	}

	heapSort(arr, 2*n-1);

	if(arr[n-1] < arr[n]){
		printf("YES");
	}else{
		printf("NO");
	}

	return 0;
}


#include <stdio.h>

int main()
{
    int n;
    int a[200];
    scanf("%d", &n);
    n *= 2;
    for(int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n; ++i) {
        int k = i;
        for(int j = i + 1; j < n; ++j) {
            if(a[k] < a[j]) {
                k = j;
            }
        }
        if(k != i) {
            int temp = a[i];
            a[i] = a[k];
            a[k] = temp;
        }
    }
    puts(a[n / 2 - 1] > a[n / 2] ? "YES" : "NO");
    return 0;
}


#include <stdio.h>

int main()
{
    int n;
    int a[200];
    scanf("%d", &n);
    n *= 2;
    for(int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n; ++i) {
        int k = i;
        for(int j = i + 1; j < n; ++j) {
            if(a[k] < a[j]) {
                k = j;
            }
        }
        if(k != i) {
            int temp = a[i];
            a[i] = a[k];
            a[k] = temp;
        }
    }
    for(int i = 0; i < n / 2; ++i) {
        if(a[i] == a[n / 2 + i]) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}


#include<stdio.h>

int func(int x,int y, long long int z[]){
	int i,count=0;
	for(i=x;i<y;i++){
		count+=z[i];
	}
	return count;
}

int main(){
	int t,i;
	long long int b[201];
	scanf("%d",&t);
	for(i=0;i<2*t;i++){
		scanf("%lld",&b[i]);
	}
	for(i=0;i<2*t-1;i++){
		for(int j=i;j<2*t;j++){
			if(b[i]<b[j]){
				int temp=b[i];
				b[i]=b[j];
				b[j]=temp;
			}
		}
	}
	if(func(0,t,b)>func(t,2*t,b)){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
}


#include<stdio.h>

int func(int x,int y, long long int z[]){
	int i,count=0;
	for(i=x;i<y;i++){
		count+=z[i];
	}
	return count;
}

int pair(int t, long long int z[]){
	int flag=1;
	for(int i=0;i<t;i++){
		if(z[i]==z[2*t-i-1]){
			flag=0;
			break;
		}
	}
	return flag;
}

int main(){
	int t,i;
	long long int b[201];
	scanf("%d",&t);
	for(i=0;i<2*t;i++){
		scanf("%lld",&b[i]);
	}
	for(i=0;i<2*t-1;i++){
		for(int j=i;j<2*t;j++){
			if(b[i]<b[j]){
				int temp=b[i];
				b[i]=b[j];
				b[j]=temp;
			}
		}
	}
	if(func(0,t,b)>func(t,2*t,b) && pair(t,b)!=0){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
}


#include <stdio.h>
#include <stdlib.h>

int compare (const void *a, const void *b) {
	return (*(int *)a - *(int *)b);
}

int main() {
	int n,i;
	scanf("%d", &n);
	int t = 2*n;
	int players[t];
	for (i = 0; i < t; i++)
		scanf("%d", &players[i]);

	qsort(players,t,sizeof(int),compare);
	if (players[n-1] < players[n])
		printf ("YES");
	else
		printf("NO");
}


#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int m;
	m=2*n;
	int a[m];
	int i, j, tmp;

	for(i=0;i<m;i++)
		scanf("%d", &a[i]);

	for(i=0;i<m-1;i++)
		for(j=0;j<m-i-1;j++)
			if(a[j]>a[j+1])
			{
				tmp=a[j];
				a[j]=a[j+1];
				a[j+1]=tmp;
			}

	int count1=0;
	int count=0;
	for(i=0;i<n;i++)
		count=count+a[i];
	for(i=n;i<m;i++)
		count1=count1+a[i];

	if(count1>count)
		printf("YES");
	else
		printf("NO");

}


#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int m;
	m=2*n;
	int a[m], w[n], l[n];
	int i, j, tmp;

	for(i=0;i<m;i++)
		scanf("%d", &a[i]);

	for(i=0;i<m-1;i++)
		for(j=0;j<m-i-1;j++)
			if(a[j]<a[j+1])
			{
				tmp=a[j];
				a[j]=a[j+1];
				a[j+1]=tmp;
			}
	/*printf("\n");
	for(i=0;i<m;i++)
		printf("%d ", a[i]);*/

	//int count1=0;
	int count=0;
	for(i=0;i<n;i++)
		w[i]=a[i];
		//printf("\n%d %d %d", a[i], a[n+i], count);
	for(i=0;i<n;i++)
		l[i]=a[i+n];

	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			if(w[i]>l[j])
				count++;

	if(count==(n*n))
		printf("YES");
	else
		printf("NO");

}


#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
int cmp(const void *a,const void *b){return(*(int*)a-*(int*)b);}
int main(){
    int n;scanf(" %d",&n);
    int a[2*n],i;
    for(i=0;i<2*n;i++)scanf(" %d",&a[i]);
    qsort(a,2*n,sizeof(int),cmp);

    a[n]>a[n-1] ? printf("yes"): printf("no") ;
    return 0;
}


#include<stdio.h>

void swap(int *a,int *b)
{
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
}

void sort(int a[],int n)
{
    int i,j;
    for(i=2*n;i>0;i--)
        for(j=0;j<i-1;j++)
            if(a[j]>a[j+1])
                swap(&a[j],&a[j+1]);
}

int main()
{
    int a[200],n,i;
    scanf("%d",&n);
    for(i=0;i<2*n;i++)
        scanf("%d",&a[i]);
    sort(a,n);
    if(a[n]==a[n-1])
        printf("NO");
    else
        printf("YES");
    return 0;
}


#include<stdio.h>

void swap(int *a,int *b)
{
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
}

void sort(int a[],int n)
{
    int i,j;
    for(i=2*n;i>0;i--)
        for(j=0;i<i;j++)
            if(a[j]>a[j+1])
                swap(&a[j],&a[j+1]);
}

int main()
{
    int a[200],n,i;
    scanf("%d",&n);
    for(i=0;i<2*n;i++)
        scanf("%d",&a[i]);
    sort(a,n);
    if(a[n]==a[n-1])
        printf("NO");
    else
        printf("YES");
    return 0;
}


#include<stdio.h>

void swap(int *a,int *b)
{
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
}

void sort(int a[],int n)
{
    int i,j;
    for(i=2*n;i>0;i--)
        for(j=0;j<i-1;j++)
            if(a[j]>a[j+1])
                swap(&a[j],&a[j+1]);
    for(i=0;i<2*n;i++)
        printf("%d ",a[i]);
}

int main()
{
    int a[200],n,i;
    scanf("%d",&n);
    for(i=0;i<2*n;i++)
        scanf("%d",&a[i]);
    sort(a,n);
    if(a[n]==a[n-1])
        printf("NO");
    else
        printf("YES");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int compar(const void *a, const void *b);
int compar(const void *a, const void *b) {
  int *x = (int *)a, *y = (int *)b;
  return *x - *y;
}

int main() {
  int n;
  scanf("%d", &n);
  int a[200];
  int i;
  for (i = 0; i < 2*n; ++i)
    scanf("%d", a + i);
  qsort(a, 2*n, sizeof(int), compar);
  if (a[n - 1] == a[n])
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}


#include <stdio.h>
#include <stdlib.h>

int cmpint(const int* a, const int* b);
int main()
{
    int n; scanf("%d", &n);
    int a[2*n];
    for(int i=0;i<2*n;i++)scanf("%d", &a[i]);
    qsort(a, sizeof(a)/sizeof(int), sizeof(a[0]), cmpint);
    a[n-1] == a[n]? printf("NO"):printf("YES");
}

int cmpint(const int* a, const int* b)
{
    return (*a - *b);
}


#include<stdio.h>
#include<stdlib.h>
int cmpr(const void * a,const void * b)
{

return ((*(int *)a)-(*(int *)b));

}

int main()
{
int n;scanf("%d",&n);
int i=0;int x;
int count=0;int arr[210];
//scanf("%d",&x);
int y=0;
for(i=0;i<(2*n);i++)
{
scanf("%d",&arr[i]);
}

qsort(arr,(2*n),sizeof(int),cmpr);
int o=0;
//for(i=0;i<2*n;i++)printf("%d ",arr[i]);
int j=2*n-1;
for(j=2*n-1;j>=n;j--)
{

    if(arr[j]>arr[j-1])count++;

}

if(count == n)printf("YES\n");
else printf("NO\n");
return 0;
}


#include<stdio.h>
#include<stdlib.h>
int cmpr(const void * a,const void * b)
{

return ((*(int *)a)-(*(int *)b));

}

int main()
{
int n;scanf("%d",&n);
int i=0;int x;
int count=0;int arr[210];
//scanf("%d",&x);
int y=0;
for(i=0;i<(2*n);i++)
{
scanf("%d",&arr[i]);
}

qsort(arr,(2*n),sizeof(int),cmpr);
int o=0;
//for(i=0;i<2*n;i++)printf("%d ",arr[i]);
int j=2*n-1;
int pivot = arr[n-1];
for(j=2*n-1;j>=(n);j--)
{

    if(arr[j]>pivot)count++;

}

if(count == n)printf("YES\n");
else printf("NO\n");
return 0;
}


#include<stdio.h>
int main()
{
int n;scanf("%d",&n);
int i=0;int x;
int count=0;
scanf("%d",&x);
int y=0;
for(i=1;i<(2*n);i++)
{
scanf("%d",&y);
if(y!=x)count++;
}
if(count == 0)printf("NO\n");
else printf("YES\n");
return 0;
}


#include <stdio.h>
#include <stdlib.h>

int num[101];

int comp(void * a, void * b)
{
	if (*(int*)a > *(int*)b)
		return 1;
	else if (*(int*)a == *(int*)b)
		return 0;
	else
		return -1;
}

int main(void)
{
	int n, a;
	scanf("%d", &n);

	for (a = 0; a < 2 * n; a = a + 1)
		scanf("%d", &num[a]);

	qsort(num,2 * n, sizeof(int), comp);
	if (num[n - 1] < num[n])
		puts("YES");
	else
		puts("NO");

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int num[101];

int comp(void * a, void * b)
{
	if (*(int*)a > *(int*)b)
		return -1;
	else if (*(int*)a == *(int*)b)
		return 0;
	else
		return 1;
}

int main(void)
{
	int n, a, cnt = 0;
	scanf("%d", &n);

	for (a = 0; a < 2 * n; a = a + 1)
		scanf("%d", &num[a]);

	qsort(num,2 * n, sizeof(int), comp);

	for (a = 0; a < n; a = a + 1)
		if (num[a] > num[a + n])
			cnt += 1;
		else
			cnt -= 1;
	if (cnt > 0)
		puts("YES");
	else
		puts("NO");

	return 0;
}


#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	int arr[2*n];
	int i=0,j=0;
	for(i=0;i<2*n;i++)
	scanf("%d ",&arr[i]);
    for(i=0;i<2*n;i++)
    {
    	for(j=i+1;j<2*n;j++)
    	{
    		if(arr[i]>arr[j])
    		{
    			int temp=arr[i];
    			arr[i]=arr[j];
    			arr[j]=temp;
			}
		}
	}
	for(i=0;i<n;i++)
    {
    for(j=n;j<2*n;j++)
	{
	if(arr[i]==arr[j])
	{
	printf("NO");
	return 0;
	}
	}
	}
	printf("YES");
}


#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	int arr[2*n];
	int i=0;
	for(i=0;i<2*n;i++)
	scanf("%d ",&arr[i]);
	int max=arr[0];
	for(i=0;i<2*n;i++)
	{
		if(max<arr[i])
		max=arr[i];
	}
	int count=0;
	for(i=0;i<2*n;i++)
	{
		if(max==arr[i])
		count++;
	}
	if(count>n)
	printf("NO");
	else
	printf("YES");
}


import time,math as mt,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
#####################################################################################
mod=10**9+7
def solve():
    n=II()
    li = []
    for i in range(n):
        x=[]
        for j in range(n):
            if i%2:
                val=pow(2,i+j)
            else:
                val=0
            x.append(val)
        li.append(x)
    for ele in li:
        print(*ele)
        stdout.flush()
    q=II()
    for _ in range(q):
        v=II()
        v=v>>1
        print(1,1)
        stdout.flush()
        x,y=1,1
        h=0
        while v:
            if h%2==0:
                if v&1:
                    x+=1
                    h+=1
                else:
                    y+=1
            else:
                if v&1:
                    y+=1
                else:
                    x+=1
                    h+=1
            v=v>>1
            print(x,y)
            stdout.flush()
     stdout.flush()
     return

t=1
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
#####################################################################################
mod=10**9+7
def solve():
    n=II()
    li = []
    for i in range(n):
        x=[]
        for j in range(n):
            if i%2:
                val=pow(2,i+j)
            else:
                val=0
            x.append(val)
        li.append(x)
    for ele in li:
        print(*ele)
    stdout.flush()
    q=II()
    for _ in range(q):
        v=II()
        v=v>>1
        print(1,1)
        x,y=1,1
        h=0
        while v:
            if h%2==0:
                if v&1:
                    x+=1
                    h+=1
                else:
                    y+=1
            else:
                if v&1:
                    y+=1
                else:
                    x+=1
                    h+=1
            v=v>>1
            print(x,y)

t=1
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
#####################################################################################
mod=10**9+7
def solve():
    n=II()
    li = []
    for i in range(n):
        x=[]
        for j in range(n):
            if i%2:
                val=pow(2,i+j)
            else:
                val=0
            x.append(val)
        li.append(x)
    for ele in li:
        print(*ele)
        stdout.flush()
    q=II()
    for _ in range(q):
        v=II()
        v=v>>1
        print(1,1)
        x,y=1,1
        h=0
        while v:
            if h%2==0:
                if v&1:
                    x+=1
                    h+=1
                else:
                    y+=1
            else:
                if v&1:
                    y+=1
                else:
                    x+=1
                    h+=1
            v=v>>1
            print(x,y)
        stdout.flush()

t=1
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
#####################################################################################
mod=10**9+7
def solve():
    n=int(input())
    li = []
    for i in range(n):
        x=[]
        for j in range(n):
            if i%2:
                val=pow(2,i+j)
            else:
                val=0
            x.append(val)
        li.append(x)
    for ele in li:
        print(*ele,flush=True)
    stdout.flush()
    q=II()
    for _ in range(q):
        v=II()
        v=v>>1
        print(1,1,flush=True)
        x,y=1,1
        h=0
        while v:
            if h%2==0:
                if v&1:
                    x+=1
                    h+=1
                else:
                    y+=1
            else:
                if v&1:
                    y+=1
                else:
                    x+=1
                    h+=1
            v=v>>1
            print(x,y,flush=True)
        stdout.flush()
    return

t=1
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
#####################################################################################
mod=10**9+7
def solve():
    n=int(input())
    li = []
    for i in range(n):
        x=[]
        for j in range(n):
            if i%2:
                val=pow(2,i+j)
            else:
                val=0
            x.append(val)
        li.append(x)
        x=[str(v) for v in x]
        print(' '.join(x))
    stdout.flush()
    q=int(input())
    for i in range(q):
        v=int(input())
        v=v>>1
        print(1,1)
        x,y=1,1
        h=0
        while v:
            if h%2==0:
                if v&1:
                    x+=1
                    h+=1
                else:
                    y+=1
            else:
                if v&1:
                    y+=1
                else:
                    x+=1
                    h+=1
            v=v>>1
            print(x,y)
        stdout.flush()
    return

t=1
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
#####################################################################################
mod=10**9+7
def solve():
    n=int(input())
    li = []
    for i in range(n):
        x=[]
        for j in range(n):
            if i%2:
                val=pow(2,i+j)
            else:
                val=0
            x.append(val)
        li.append(x)
    for ele in li:
        print(*ele,flush=True)
    stdout.flush()
    q=int(input())
    for _ in range(q):
        v=int(input())
        v=v>>1
        print(1,1,flush=True)
        x,y=1,1
        h=0
        while v:
            if h%2==0:
                if v&1:
                    x+=1
                    h+=1
                else:
                    y+=1
            else:
                if v&1:
                    y+=1
                else:
                    x+=1
                    h+=1
            v=v>>1
            print(x,y,flush=True)
        stdout.flush()
    return

t=1
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
#####################################################################################
mod=10**9+7
def solve():
    n=II()
    li=[[0 for j in range(n)] for i in range(n)]
    for ele in li:
        print(*ele)
    stdout.flush()
    q=II()
    for _ in range(q):
        v=II()
        for i in range(1,n+1):
            print(1,i)
        for i in range(2,n+1):
            print(i,n)
        stdout.flush()

t=1
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
#####################################################################################
mod=10**9+7
def solve():
    n=II()
    li = []
    for i in range(n):
        x=[]
        for j in range(n):
            if i%2:
                val=pow(2,i+j)
            else:
                val=0
            x.append(val)
        li.append(x)
    for ele in li:
        print(*ele)
        stdout.flush()
    q=II()
    for _ in range(q):
        v=II()
        v=v>>1
        print(1,1)
        stdout.flush()
        x,y=1,1
        h=0
        while v:
            if h%2==0:
                if v&1:
                    x+=1
                    h+=1
                else:
                    y+=1
            else:
                if v&1:
                    y+=1
                else:
                    x+=1
                    h+=1
            v=v>>1
            print(x,y)
            stdout.flush()
    stdout.flush()
    return

t=1
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
#####################################################################################
mod=10**9+7
def solve():
    n=II()
    li = []
    for i in range(n):
        x=[]
        for j in range(n):
            if i%2:
                val=pow(2,i+j)
            else:
                val=0
            x.append(val)
        li.append(x)
    for ele in li:
        print(*ele,flush=True)
    q=II()
    for _ in range(q):
        v=II()
        v=v>>1
        print(1,1,flush=True)
        x,y=1,1
        h=0
        while v:
            if h%2==0:
                if v&1:
                    x+=1
                    h+=1
                else:
                    y+=1
            else:
                if v&1:
                    y+=1
                else:
                    x+=1
                    h+=1
            v=v>>1
            print(x,y,flush=True)
    return

t=1
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
#####################################################################################
mod=10**9+7
def solve():
    n=int(input())
    li = []
    for i in range(n):
        x=[]
        for j in range(n):
            if i%2:
                val=pow(2,i+j)
            else:
                val=0
            x.append(val)
        li.append(x)
        x=[str(v) for v in x]
        print(' '.join(x))
    stdout.flush()
    q=int(input())
    for i in range(q):
        v=int(input())
        v=v>>1
        print(1,1)
        x,y=1,1
        h=0
        while v:
            if h%2==0:
                if v&1:
                    x+=1
                    h+=1
                else:
                    y+=1
            else:
                if v&1:
                    y+=1
                else:
                    x+=1
                    h+=1
            v=v>>1
            print(x,y)
        x+=1
        if x<=n:
            for i in range(y,n+1):
                print(x,i)
        stdout.flush()
    return

t=1
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
#####################################################################################
mod=10**9+7
def solve():
    n=int(input())
    li = []
    for i in range(n):
        x=[]
        for j in range(n):
            if i%2:
                val=pow(2,i+j)
            else:
                val=0
            x.append(val)
        li.append(x)
    for ele in li:
        print(*ele,flush=True)
    stout.flush()
    q=II()
    for _ in range(q):
        v=II()
        v=v>>1
        print(1,1,flush=True)
        x,y=1,1
        h=0
        while v:
            if h%2==0:
                if v&1:
                    x+=1
                    h+=1
                else:
                    y+=1
            else:
                if v&1:
                    y+=1
                else:
                    x+=1
                    h+=1
            v=v>>1
            print(x,y,flush=True)
        stdout.flush()
    return

t=1
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
#####################################################################################
mod=10**9+7
def solve():
    n=II()
    li=[[0 for j in range(n)] for i in range(n)]
    for ele in li:
        print(*ele)
    #stdout.flush()
    q=II()
    for _ in range(q):
        v=II()
        for i in range(1,n+1):
            print(1,i)
        for i in range(2,n+1):
            print(i,n)
        #stdout.flush()

t=1
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import sys
input = sys.stdin.readline
'''def print(val):
    sys.stdout.write(str(val) + '\n')'''
def prog():
    n = int(input())
    grid = [[0]*n for i in range(n)]
    for i in range(1,n,2):
        for j in range(n):
            grid[i][j] = 1 << (i + j)
    for i in range(n):
        print(*grid[i])
    sys.stdout.flush()

    q = int(input().strip())
    for _ in range(q):
        path = int(input().strip())
        keypoints = []
        check = 2
        curr = 1
        while check <= path:
            if check & path:
                keypoints.append(curr)
            curr += 1
            check <<= 1

        path = [[1,1]]
        point = 0
        lox = 1
        loy = 1
        while lox != n or loy != n:
            #print(lox,loy,point)
            if grid[lox-1][loy-1] == 0:
                if point == len(keypoints):
                    loy += 1
                    path.append([lox,loy])
                else:
                    while lox + loy - 2 != keypoints[point] - 1:
                        loy += 1
                        path.append([lox,loy])
                    if lox != n:
                        lox += 1
                        path.append([lox,loy])
                        point += 1
            else:
                while point != len(keypoints) and \
                      keypoints[point-1] + 1 == keypoints[point]:
                    loy += 1
                    path.append([lox,loy])
                    point += 1
                if lox != n:
                    lox += 1
                    path.append([lox,loy])

        for i in path:
            print(*i)
            sys.stdout.flush()
prog()


def _i():
    return int(input())

def _il():
    return [int(x) for x in input().split()]

def _iil():
    n = _i()
    a = _il()
    assert n == len(a)
    return a

def solve():
    n = _i()
    nb = [[0]*n for _ in range(n)]
    for i in range(n):
        nb[i][0] = 1
        nb[0][i] = 1
    for i in range(1, n):
        for j in range(1, n):
            nb[i][j] = nb[i-1][j] + nb[i][j-1]
    grid = [[0]*n for _ in range(n)]
    for i in range(1, n):
        sofar = nb[i-1][n-1]
        for j in range(n-2, -1, -1):
            grid[i][j] = sofar \
                - sum(grid[k][j] for k in range(i)) \
                - sum(grid[i][k] for k in range(j+1, n))
            sofar += nb[i-1][j]
    for line in grid:
        print(*line, flush=True)
    q = _i()
    for _ in range(q):
        trace = []
        k = _i()
        i = n-1
        for j in range(n-2, -1, -1):
            for l in range(i, -1, -1):
                k -= grid[l][j+1]
                if sum(grid[m][j] for m in range(l+1)) <= k:
                    i = l
                    trace.append(i)
                    break
            else:
                i = 0
                trace.append(i)
        a = 0
        for j, i in enumerate(trace[::-1]):
            for x in range(a, i+1):
                print(x+1, j+1, flush=True)
            a = i
        for x in range(a, n):
            print(x+1, n, flush=True)

solve()


from collections import defaultdict as dd
import math
from itertools import combinations
import operator as op
from functools import reduce
import heapq
from sys import stdout

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))

n = nn()

ans =  [[0 for i in range(n)] for j in range(n)]

for i in range(n):
	for j in range(n):
		if i%2==1:
			ans[i][j]=2**(i+j-1)

#print(ans)

for row in ans:
	print(*row)
	stdout.flush()

q= nn()

for _ in range(q):
	num = nn()
	cur = [1,1]
	print(*cur)
	stdout.flush()
	val = 0
	for i in range(2*n-2):
		if num%2+(cur[0]-1)%2:
			cur[0]+=1
		else:
			cur[1]+=1
		num = num>>1
		print(*cur)
		val += ans[cur[0]-1][cur[1]-1]
		stdout.flush()
	#print(val)


from collections import defaultdict as dd
import math
from itertools import combinations
import operator as op
from functools import reduce
import heapq
from sys import stdout

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))

n = nn()

ans =  [[0 for i in range(n)] for j in range(n)]

for i in range(n):
	for j in range(n):
		if i%2==1:
			ans[i][j]=2**(i+j-1)

#print(ans)

for row in ans:
	print(*row)
	stdout.flush()

q= nn()

for _ in range(q):
	num = nn()
	cur = [1,1]
	print(*cur)
	stdout.flush()
	val = 0
	for i in range(2*n-2):
		if (num+(cur[0]-1))%2:
			cur[0]+=1
		else:
			cur[1]+=1
		num = num>>1
		print(*cur)
		val += ans[cur[0]-1][cur[1]-1]
		stdout.flush()
		#print(val,num)


#Code by Sounak, IIESTS
#------------------------------warmup----------------------------

import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now-----------------------------------------------------
n=int(input())
a=[[1 for i in range (n)]for j in range (n)]
prev=1
s=1
for i in range (n-2,-1,-1):
    prev=s+1
    for j in range (n-1,0,-1):
        prev+=a[i+1][j-1]
        a[i][j]=prev
    a[i][0]=prev
    s+=a[i][-1]
for i in a:
    print(*i,flush=True)
    #sys.stdout.flush()
for q in range (int(input())):
    k=int(input())
    copy=k
    x=1
    y=1
    print(x,y,flush=True)
    #sys.stdout.flush()
    k-=a[0][0]
    while True:
        if x==n and y==n:
            break
        elif x==n:
            k-=a[n-1][y]
            y+=1
            print(x,y,flush=True)
            #sys.stdout.flush()
        elif y==n:
            k-=a[x][n-1]
            x+=1
            print(x,y,flush=True)
            #sys.stdout.flush()
        else:
            if k>=a[x-1][y]:
                k-=a[x-1][y]
                y+=1
                print(x,y,flush=True)
                #sys.stdout.flush()
            else:
                k-=a[x][y-1]
                x+=1
                print(x,y,flush=True)
                #sys.stdout.flush()


#Code by Sounak, IIESTS
#------------------------------warmup----------------------------

import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now-----------------------------------------------------
n=int(input())
a=[[0 for i in range (n)]for j in range (n)]
prev=1
s=0
for i in range (n-1,-1,-1):
    for j in range (n):
        a[i][j]=prev
        s+=prev
    prev=s+1
for i in a:
    print(*i,flush=True)
    #sys.stdout.flush()
for q in range (int(input())):
    k=int(input())
    copy=k
    x=1
    y=1
    print(x,y,flush=True)
    #sys.stdout.flush()
    k-=a[0][0]
    while True:
        if x==n and y==n:
            break
        elif x==n:
            k-=a[n-1][y]
            y+=1
            print(x,y,flush=True)
            #sys.stdout.flush()
        elif y==n:
            k-=a[x][n-1]
            x+=1
            print(x,y,flush=True)
            #sys.stdout.flush()
        else:
            if k>=a[x-1][y]:
                k-=a[x-1][y]
                y+=1
                print(x,y,flush=True)
                #sys.stdout.flush()
            else:
                k-=a[x][y-1]
                x+=1
                print(x,y,flush=True)
                #sys.stdout.flush()


#Code by Sounak, IIESTS
#------------------------------warmup----------------------------

import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now-----------------------------------------------------
n=int(input())
a=[[0 for i in range (n)]for j in range (n)]
prev=1
s=0
for i in range (n-1,-1,-1):
    for j in range (n):
        a[i][j]=prev
        s+=prev
    prev=s+1
for i in a:
    print(*i)
    sys.stdout.flush()
k=int(input())
copy=k
x=1
y=1
print(x,y)
sys.stdout.flush()
k-=a[0][0]
while True:
    if x==n and y==n:
        break
    elif x==n:
        k-=a[n-1][y]
        y+=1
        print(x,y)
        sys.stdout.flush()
    elif y==n:
        k-=a[x][n-1]
        x+=1
        print(x,y)
        sys.stdout.flush()
    else:
        if k>=a[x-1][y]:
            k-=a[x-1][y]
            y+=1
            print(x,y)
            sys.stdout.flush()
        else:
            k-=a[x][y-1]
            x+=1
            print(x,y)
            sys.stdout.flush()


#Code by Sounak, IIESTS
#------------------------------warmup----------------------------

import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now-----------------------------------------------------
n=int(input())
a=[[0 for i in range (n)]for j in range (n)]
for k in range (n):
    a[n-2][k]=1
prev=1
s=1
for i in range (n-3,-1,-1):
    prev=s+1
    for j in range (n-1,0,-1):
        prev+=a[i+1][j-1]
        a[i][j]=prev
    a[i][0]=prev
    s=a[i][-1]
for i in a:
    print(*i,flush=True)
    #sys.stdout.flush()
for q in range (int(input())):
    k=int(input())
    copy=k
    x=1
    y=1
    print(x,y,flush=True)
    #sys.stdout.flush()
    k-=a[0][0]
    while True:
        if x==n and y==n:
            break
        elif x==n:
            k-=a[n-1][y]
            y+=1
            print(x,y,flush=True)
            #sys.stdout.flush()
        elif y==n:
            k-=a[x][n-1]
            x+=1
            print(x,y,flush=True)
            #sys.stdout.flush()
        else:
            if k>=a[x-1][y]:
                k-=a[x-1][y]
                y+=1
                print(x,y,flush=True)
                #sys.stdout.flush()
            else:
                k-=a[x][y-1]
                x+=1
                print(x,y,flush=True)
                #sys.stdout.flush()


#Code by Sounak, IIESTS
#------------------------------warmup----------------------------

import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now-----------------------------------------------------
n=int(input())
a=[[0 for i in range(n)]for j in range(n)]
for i in range(n):
    for j in range(n):
        if i%2==0:
            a[i][j]=2**(i+j)
for i in a:
    print(*i,flush=True)
for ik in range(int(input())):
    k=int(input())
    x=0
    y=0
    print(1,1)
    for i in range(2*n-2):
        if x==n-1:
            y+=1
        elif y==n-1:
            x+=1
        else:
            e=2**(x+y+1)
            if x%2==0:
                if e&k>0:
                    y+=1
                else:
                    x+=1
            else:
                if e&k>0:
                    x+=1
                else:
                    y+=1
        print(x+1,y+1,flush=True)


#Code by Sounak, IIESTS
#------------------------------warmup----------------------------

import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now-----------------------------------------------------
n=int(input())
a=[[0 for i in range (n)]for j in range (n)]
for k in range (n):
    a[n-2][k]=1
prev=1
s=1
for i in range (n-3,-1,-1):
    prev=s+1
    for j in range (n-1,0,-1):
        prev+=a[i+1][j-1]
        a[i][j]=prev
    a[i][0]=prev
    s+=a[i][-1]
for i in a:
    print(*i,flush=True)
    #sys.stdout.flush()
for q in range (int(input())):
    k=int(input())
    copy=k
    x=1
    y=1
    print(x,y,flush=True)
    #sys.stdout.flush()
    k-=a[0][0]
    while True:
        if x==n and y==n:
            break
        elif x==n:
            k-=a[n-1][y]
            y+=1
            print(x,y,flush=True)
            #sys.stdout.flush()
        elif y==n:
            k-=a[x][n-1]
            x+=1
            print(x,y,flush=True)
            #sys.stdout.flush()
        else:
            if k>=a[x-1][y]:
                k-=a[x-1][y]
                y+=1
                print(x,y,flush=True)
                #sys.stdout.flush()
            else:
                k-=a[x][y-1]
                x+=1
                print(x,y,flush=True)
                #sys.stdout.flush()


#Code by Sounak, IIESTS
#------------------------------warmup----------------------------

import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now-----------------------------------------------------
n=int(input())
a=[[0 for i in range (n)]for j in range (n)]
prev=1
s=0
for i in range (n-1,-1,-1):
    for j in range (n):
        a[i][j]=prev
        s+=prev
    prev=prev*n+1
for i in a:
    print(*i,flush=True)
    #sys.stdout.flush()
for q in range (int(input())):
    k=int(input())
    copy=k
    x=1
    y=1
    print(x,y,flush=True)
    #sys.stdout.flush()
    k-=a[0][0]
    while True:
        if x==n and y==n:
            break
        elif x==n:
            k-=a[n-1][y]
            y+=1
            print(x,y,flush=True)
            #sys.stdout.flush()
        elif y==n:
            k-=a[x][n-1]
            x+=1
            print(x,y,flush=True)
            #sys.stdout.flush()
        else:
            if k>=a[x-1][y]:
                k-=a[x-1][y]
                y+=1
                print(x,y,flush=True)
                #sys.stdout.flush()
            else:
                k-=a[x][y-1]
                x+=1
                print(x,y,flush=True)
                #sys.stdout.flush()


#Code by Sounak, IIESTS
#------------------------------warmup----------------------------

import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now-----------------------------------------------------
n=int(input())
a=[[0 for i in range (n)]for j in range (n)]
for k in range (n):
    a[n-2][k]=1
prev=1
s=1
for i in range (n-3,-1,-1):
    prev=s+1
    for j in range (n-1,0,-1):
        a[i][j]=a[i+1][j]+a[i+1][j-1]+1
        prev=a[i][j]
    a[i][0]=prev
for i in a:
    print(*i,flush=True)
    #sys.stdout.flush()
for q in range (int(input())):
    k=int(input())
    copy=k
    x=1
    y=1
    print(x,y,flush=True)
    #sys.stdout.flush()
    k-=a[0][0]
    while True:
        if x==n and y==n:
            break
        elif x==n:
            k-=a[n-1][y]
            y+=1
            print(x,y,flush=True)
            #sys.stdout.flush()
        elif y==n:
            k-=a[x][n-1]
            x+=1
            print(x,y,flush=True)
            #sys.stdout.flush()
        else:
            if k>=a[x-1][y]:
                k-=a[x-1][y]
                y+=1
                print(x,y,flush=True)
                #sys.stdout.flush()
            else:
                k-=a[x][y-1]
                x+=1
                print(x,y,flush=True)
                #sys.stdout.flush()


n = int(input())
arr=[[0 for i in range(n)]for j in range(int(n))]

for i in range(n):
    if i&1 != 1:
        for j in range(n):
            arr[i][j] = (i+j)
f=lambda  x: 1<<x if x !=0 else 0
for i in arr:
    print(*[f(j) for j in i],flush=True)
q=int(input())
for _ in range(q):
    w = int(input())
    x=0
    y=0
    for i in range(2*n-2):
        print(x+1,y+1)
        if x == n-1:
            y=y+1
        elif y == n-1:
            x=x+1
        else:
            x0 = x+1
            y0 = y
            x1= x
            y1 = y+1
            if arr[x0][y0] != 0:
                if w&(1<<arr[x0][y0]) > 0:
                    x=x0
                    y=y0
                else:
                    x=x1
                    y=y1
            else:
                if w&(1<<arr[x1][y1]) > 0:
                    x=x1
                    y=y1
                else:
                    x=x0
                    y=y0

    print(x+1,y+1)


def make_map(n):
    X = [[0]*n for _ in range(n)]
    for i in range(1, 2*n-2):
        for j in range(min(i+1, n)):
            if i-j < n and j%2:
                X[j][i-j] = 2**(i-1)
    for x in X:
        print(*x, flush=True)
    return X

#make_map(4)
N, = map(int, input().split())
X = make_map(N)
Q, = map(int, input().split())
for _ in range(Q):
    m, = map(int, input().split())
    R = [(0, 0)]
    for i in range(1, 2*N-2):
        cx, cy = R[-1]
        tmp = m & 2**(i-1)
        for x, y in [(cx+1, cy), (cx, cy+1)]:
            if x == N or y == N:
                continue
            if not(X[x][y] ^ tmp):
                R.append((x, y))
                break
    R.append((N-1, N-1))
    for x, y in R:
        print(x+1, y+1, flush=True)


import sys
input=sys.stdin.readline

N=int(input())
A=[]
for i in range(N):
    A.append([i%2]*N)

B=[[0 for i in range(N)] for j in range(N)]

ts=N+N-2
for i in range(N):
    for j in range(N):
        v=ts-(i+j)
        B[i][j]=int(str(A[i][j])+'0'*(v),2)

for i in B:
    print(*i)
    sys.stdout.flush()

Q=int(input())

for i in range(Q):
    a=int(input())
    v=bin(a).replace("0b","")
    v='0'*(ts-len(v))+v
    x,y=1,1
    print(x,y)
    sys.stdout.flush()
    for i in v:
        if (i=='0' and x%2==0):
            x,y=x,y+1

        elif(i=='0' and x%2!=0):
            x,y=x+1,y

        elif (i=='1' and x%2==0):
            x,y=x+1,y

        else:
            x,y=x,y+1

        print(x,y)
        sys.stdout.flush()


import sys
input=sys.stdin.readline

N=int(input())
for i in range(N):
    A=[0]*N
    print(*A)
    sys.stdout.flush()

P=[]
for i in range(N):
    P.append([1,i+1])

for j in range(1,N):
    P.append([j+1,N])
Q=int(input())

for i in range(Q):
    a=int(input())
    for i in P:
        print(*i)
        sys.stdout.flush()


import sys
input=sys.stdin.readline

N=int(input())
A=[]
for i in range(N):
    A.append([i%2]*N)

B=[[0 for i in range(N)] for j in range(N)]

ts=N+N-2
for i in range(N):
    for j in range(N):
        v=ts-(i+j)
        B[i][j]=int(str(A[i][j])+'0'*(v),2)

for i in B:
    print(*i)
    sys.stdout.flush()

Q=int(input())

for i in range(Q):
    a=int(input())
    v=bin(a).replace("0b","")
    v='0'*(ts-len(v))+v
    x,y=1,1
    #print(v)
    print(x,y)
    sys.stdout.flush()
    for i in v:
        if (i=='0' and x%2!=0):
            x,y=x,y+1

        elif(i=='0' and x%2==0):
            x,y=x+1,y

        elif (i=='1' and x%2!=0):
            x,y=x+1,y

        else:
            x,y=x,y+1

        print(x,y)
        sys.stdout.flush()


import sys
input=sys.stdin.readline

N=int(input())
for i in range(N):
    A=[0]*N
    print(*A)
    sys.stdout.flush()

P=[]
for i in range(N):
    P.append([1,i+1])

for j in range(N):
    P.append([N,j+1])
Q=int(input())

for i in range(Q):
    a=int(input())
    for i in P:
        print(*i)
        sys.stdout.flush()


import sys

arr = [[0]*26 for i in range(26)]

mymx = [[0]*26 for i in range(26)]
mymn = [[0]*26 for i in range(26)]
N = int(input())

for i in range(1,N):
  for j in range(N):
    if j != N-1:
      arr[i][j] = mymx[i-1][j+1]-min(mymn[i-1][j],mymn[i][j-1])+1
    if j == 0:
      mymx[i][j] = mymx[i-1][j]+arr[i][j]
      mymn[i][j] = mymn[i-1][j]+arr[i][j]
    else:
      mymx[i][j] = max(mymx[i-1][j], mymx[i][j-1])+arr[i][j]
      mymn[i][j] = min(mymn[i-1][j], mymn[i][j-1])+arr[i][j]

for i in range(N):
  for j in range(N):
    print(arr[i][j],end=' ')
  print()

sys.stdout.flush()

def solve(k):
  kk=k
  L = []
  cx,cy = N-1,N-1
  while True:
    k -= arr[cx][cy]
    L.append((cx,cy))

    if cx == 0:
      while cy > 0:
        cy -= 1
        L.append((cx,cy))
      break

    if cy == 0:
      while cx > 0:
        cx -= 1
        L.append((cx,cy))
      break

#    print("----",cx,cy,mymx[cx-1][cy],k)

    if k > mymx[cx-1][cy]:
      cy -= 1

    else:
      cx -= 1

  L.reverse()
  for cx,cy in L:
    print(cx+1, cy+1)
  sys.stdout.flush()

q = int(input())
for _ in range(q):
  k = int(input())
  solve(k)


import sys

arr = [[0]*26 for i in range(26)]

mymx = [[0]*26 for i in range(26)]
mymn = [[0]*26 for i in range(26)]
N = int(input())

for i in range(1,N):
  for j in range(N):
    if j != N-1:
      arr[i][j] = mymx[i-1][j+1]-min(mymn[i-1][j],mymn[i][j-1])+1
    if j == 0:
      mymx[i][j] = mymx[i-1][j]+arr[i][j]
      mymn[i][j] = mymn[i-1][j]+arr[i][j]
    else:
      mymx[i][j] = max(mymx[i-1][j], mymx[i][j-1])+arr[i][j]
      mymn[i][j] = min(mymn[i-1][j], mymn[i][j-1])+arr[i][j]

for i in range(N):
  for j in range(N):
    print(arr[i][j],end=' ')
  print()

sys.stdout.flush()

def solve(k):
  kk=k
  L = []
  cx,cy = N-1,N-1
  while True:
    k -= arr[cx][cy]
    L.append((cx,cy))

    if cx == 0:
      while cy > 0:
        cy -= 1
        L.append((cx,cy))
      break

    if cy == 0:
      while cx > 0:
        cx -= 1
        L.append((cx,cy))
      break

#    print("----",cx,cy,mymx[cx-1][cy],k)

    if k > mymx[cx-1][cy]:
      cy -= 1

    else:
      cx -= 1

  L.reverse()
  for cx,cy in L:
    print(cx, cy)
  sys.stdout.flush()

q = int(input())
for _ in range(q):
  k = int(input())
  solve(k)


from sys import stdin
input = stdin.readline

n = int(input())
for i in range(n):
	for j in range(n):
		if i & 1:
			print(1 << i + j, end=' ')
		else:
			print(0, end=' ')
	print(flush=True)
for _ in range(int(input())):
	a = int(input())
	x = y = 0
	print(1, 1, flush=True)
	for i in range(1, 2 * n - 1):
		if x & 1:
			if (a >> i) & 1:
				y += 1
			else:
				x += 1
		else:
			if (a >> i) & 1:
				x += 1
			else:
				y += 1
		print(x + 1, y + 1, flush=True)


import sys
input = sys.stdin.readline

n=int(input())

A=[[0]*n for i in range(n)]
S=[[0]*n for i in range(n)]
S2=[[0]*n for i in range(n)]
S3=[[0]*n for i in range(n)]

for i in range(1,n):
    A[i][n-2]=1

for i in range(1,n):
    S[i][n-2]=A[i][n-2]+S[i-1][n-2]
    S3[i][n-2]=i

for i in range(n-1,0,-1):
    S2[i][n-2]=A[i][n-2]+S2[i][n-1]

#for a in A:
#    print(*a)
#print()
#for a in S:
#    print(*a)
#print()
#for a in S2:
#    print(*a)
#print()

for j in range(n-3,-1,-1):
    S3[0][j]=S3[-1][j+1]
    for i in range(1,n):
        A[i][j]=S3[i-1][j]+1-S[i-1][j]-S2[i][j+1]
        S[i][j]=S[i-1][j]+A[i][j]
        S2[i][j]=S2[i][j+1]+A[i][j]
        S3[i][j]=S3[i-1][j]+A[i][j]-A[i-1][j+1]

for a in A:
    print(*a,flush=True)
#print()
#for a in S:
#    print(*a)
#print()
#for a in S2:
#    print(*a)
#print()
#for a in S3:
#    print(*a)
#print()

q=int(input())

def calc(x,y):
    SC=0
    for i in range(x,n):
        SC+=A[i][y]
    for i in range(y+1,n):
        SC+=A[n-1][i]
    return SC

for tests in range(q):
    k=int(input())
    ANS=[]
    X=0
    Y=0
    score=0

    while X!=n-1 or Y!=n-1:
        #print(X,Y)
        ANS.append((X+1,Y+1))

        if Y==n-1:
            X+=1
            score+=A[X][Y]
            continue

        if X==n-1:
            Y+=1
            score+=A[X][Y]
            continue

        if Y!=n-1:
            if calc(X,Y+1)+score<k:
                X+=1
                score+=A[X][Y]
                continue
        Y+=1
        score+=A[X][Y]

    ANS.append((n,n))

    for x,y in ANS:
        print(x,y,flush=True)


import sys
input = sys.stdin.readline

n=int(input())

A=[]
B=[]
for j in range(n):
    A.append([1<<(i+j*n) for i in range(n)])
    B.append([i+j*n for i in range(n)])

for a in A:
    print(*a,flush=True)

q=int(input())
for tests in range(q):
    k=int(input())

    Q=[(0,0)]
    ANS=[]

    while Q:
        x,y=Q.pop()
        ANS.append((x+1,y+1))
        if x==n-1 and y==n-1:
            break

        if x+1<n and k & (1<<(B[x+1][y])) != 0:
            Q.append((x+1,y))
        else:
            Q.append((x,y+1))

    for x,y in ANS:
        print(x,y,flush=True)


DEBUG = True
N = int(input())

Grid = [[1<<(i+j-1) if i+j != 0 else 0 for i in range(N)] for j in range(N)]
for i in range(1, N, 2):
    for j in range(N):
        Grid[i][j] = 0

for g in Grid:
    print(' '.join(map(str, g)))

Q = int(input())
for _ in range(Q):
    i, j = 0, 0
    Ans = [(0, 0)]
    X = int(input())
    for _ in range(2*N-2):
        if i == N-1:
            Ans.append((i, j+1))
        elif j == N-1:
            Ans.append((i+1, j))
        else:
            if (X & 1 and Grid[i+1][j]) or (not X & 1 and not Grid[i+1][j]):
                i += 1
            else:
                j += 1
            Ans.append((i, j))
            X >>= 1

    Ans = ['{} {}'.format(a+1, b+1) for a, b in Ans]
    print('\n'.join(Ans))


DEBUG = True
N = int(input())

Grid = [[1<<(i+j-1) if i+j != 0 else 0 for i in range(N)] for j in range(N)]
for i in range(1, N, 2):
    for j in range(N):
        Grid[i][j] = 0

for g in Grid:
    print(' '.join(map(str, g)))

Q = int(input())
for _ in range(Q):
    i, j = 0, 0
    Ans = [(0, 0)]
    X = int(input())
    for _ in range(2*N-2):
        if i == N-1:
            j += 1
        elif j == N-1:
            i += 1
        else:
            if (X & 1 and Grid[i+1][j]) or (not X & 1 and not Grid[i+1][j]):
                i += 1
            else:
                j += 1
            X >>= 1
        Ans.append((i, j))

    Ans = ['{} {}'.format(a+1, b+1) for a, b in Ans]
    print('\n'.join(Ans))


import sys
def nxt():
    s = input()
    while not s:
        s = input()
    return int(s)

def main():
    (n,) = map(int, input().split(' '))
    a = []
    z = 1
    for i in range(n):
        b = []
        for j in range(n):
            b.append(z)
            print(z, end=" ")
            z *= 2
        a.append(b)
        print()
    sys.stdout.flush()

    for _ in range(nxt()):
        k = nxt()
        i = 0
        j = 0
        print(1, 1)
        while i<n-1 or j < n-1:
            if i == n-1:
                j+=1
            elif j == n-1:
                i+=1
            else:
                if a[i+1][j] & k == a[i+1][j]:
                    i +=1
                else:
                    j+=1
            print(i+1, j+1)

        print()
        sys.stdout.flush()

#for _ in range(int(input())):
main()


import sys

def pow(i,j):
    s = i+j
    if i % 2 ==0:
        return 0
    return 2**s

def nxt():
    s = input()
    while not s:
        s = input()
    return int(s)

def main():
    (n,) = map(int, input().split(' '))
    a = []

    for i in range(n):
        b = []
        for j in range(n):
            z = pow(i,j)
            b.append(z)
            print(z, end=" ")
        a.append(b)
        print()
    sys.stdout.flush()

    for _ in range(nxt()):
        k = nxt()
        i = 0
        j = 0
        print(1, 1)
        while i < n - 1 or j < n - 1:
            if i == n - 1:
                j += 1
            elif j == n - 1:
                i += 1
            else:
                if  a[i + 1][j]>0:
                    if a[i + 1][j] & k == a[i + 1][j]:
                        i += 1
                    else:
                        j += 1
                else:
                    if a[i ][j+1] & k == a[i ][j+1]:
                        j += 1
                    else:
                        i += 1

            print(i + 1, j + 1)

        print()
        sys.stdout.flush()

# for _ in range(int(input())):
main()


import sys,math #Коля, привет!
n,field=int(input()),[]
for i in range(n):
    if i%2:field.append([2**j*4**(i//2) for j in range(n)])
    else:field.append([0 for j in range(n)])
for row in field:print(" ".join(map(str,row)))
for i in range(int(input())):
    path,x,y,k=[],n-1,n-1,int(input())
    bitmask=list(reversed(list(map(lambda a:bool(int(a)),str(bin(k)[2:])))))
    for j in range(2*(n-1)):
        if all((x,y)):
            if y%2:
                if bitmask[int(math.log((field[y][x-1]),2))]:x-=1
                else:y-=1
            else:
                if bitmask[int(math.log((field[y-1][x]),2))]:y-=1
                else:x-=1
        else:
            if not x:y-=1
            else:x-=1
        path.insert(0,(x,y))
    for coords in path:print(" ".join(map(str,coords)));sys.stdout.flush()


import sys,math #Коля, привет!
n,field=int(input()),[]
for i in range(n):
    if i%2:field.append([2**j*4**(i//2) for j in range(n)])
    else:field.append([0 for j in range(n)])
for row in field:print(" ".join(map(str,row)))
for i in range(int(input())):
    path,x,y,k=[(n-1,n-1)],n-1,n-1,int(input())
    bitmask=list(reversed(list(map(lambda a:bool(int(a)),str(bin(k)[2:])))))
    for j in range(2*(n-1)):
        if all((x,y)):
            if y%2:
                if bitmask[int(math.log((field[y][x-1]),2))]:x-=1
                else:y-=1
            else:
                if bitmask[int(math.log((field[y-1][x]),2))]:y-=1
                else:x-=1
        else:
            if not x:y-=1
            else:x-=1
        path.insert(0,(x,y))
    for coords in path:print(" ".join(map(lambda a:str(a+1),reversed(coords))));sys.stdout.flush()


import sys,math #Коля, привет!
n,field=int(input()),[]
for i in range(n):
    if i%2:field.append([2**j*4**(i//2) for j in range(n)])
    else:field.append([0 for j in range(n)])
for row in field:print(" ".join(map(str,row)))
for i in range(int(input())):
    path,x,y,k=[(n-1,n-1)],n-1,n-1,int(input())
    bitmask=list(reversed(list(map(lambda a:bool(int(a)),str(bin(k)[2:])))))+[False for j in range(2*n)]
    for j in range(2*(n-1)):
        if all([x,y]):
            if y%2:
                if bitmask[int(math.log((field[y][x-1]),2))]:x-=1
                else:y-=1
            else:
                if bitmask[int(math.log((field[y-1][x]),2))]:y-=1
                else:x-=1
        else:
            if not x:y-=1
            else:x-=1
        path.insert(0,(x,y))
    for coords in path:print(" ".join(map(lambda a:str(a+1),reversed(coords))));sys.stdout.flush()


import sys,math #Коля, привет!
n=int(input())
for i in range(n):
    if i%2:print(" ".join(map(str,[2**j*4**(i//2) for j in range(n)])))
    else:print(" ".join(map(str,[0 for j in range(n)])))
for i in range(int(input())):
    path,x,y,k=[(n-1,n-1)],n-1,n-1,int(input())
    bitmask=list(reversed(list(map(lambda a:bool(int(a)),str(bin(k)[2:])))))+[False for j in range(2*n)]
    for j in range(2*(n-1)):
        if all([x,y]):
            if y%2:
                if bitmask[y-2+x]:x-=1
                else:y-=1
            else:
                if bitmask[y+x]:y-=1
                else:x-=1
        else:
            if not x:y-=1
            else:x-=1
        path.insert(0,(x,y))
    for coords in path:print(" ".join(map(lambda a:str(a+1),reversed(coords))));sys.stdout.flush()


import sys,math #Коля, привет!
n,field=int(input()),[]
for i in range(n):
    if i%2:field.append([2**j*4**(i//2) for j in range(n)])
    else:field.append([0 for j in range(n)])
for row in field:print(" ".join(map(str,row)))
for i in range(int(input())):
    path,x,y,k=[(3,3)],n-1,n-1,int(input())
    bitmask=list(reversed(list(map(lambda a:bool(int(a)),str(bin(k)[2:])))))
    for j in range(2*(n-1)):
        if all((x,y)):
            if y%2:
                if bitmask[int(math.log((field[y][x-1]),2))]:x-=1
                else:y-=1
            else:
                if bitmask[int(math.log((field[y-1][x]),2))]:y-=1
                else:x-=1
        else:
            if not x:y-=1
            else:x-=1
        path.insert(0,(x,y))
    for coords in path:print(" ".join(map(str,coords)));sys.stdout.flush()


import sys,math #Коля, привет!
n,field=int(input()),[]
for i in range(n):
    if i%2:field.append([2**j*4**(i//2) for j in range(n)])
    else:field.append([0 for j in range(n)])
for row in field:print(" ".join(map(str,row)))
for i in range(int(input())):
    path,x,y,k=[(3,3)],n-1,n-1,int(input())
    bitmask=list(reversed(list(map(lambda a:bool(int(a)),str(bin(k)[2:])))))
    for j in range(2*(n-1)):
        if all((x,y)):
            if y%2:
                if bitmask[int(math.log((field[y][x-1]),2))]:x-=1
                else:y-=1
            else:
                if bitmask[int(math.log((field[y-1][x]),2))]:y-=1
                else:x-=1
        else:
            if not x:y-=1
            else:x-=1
        path.insert(0,(x,y))
    for coords in path:print(" ".join(map(lambda a:str(a+1),coords)));sys.stdout.flush()


import sys,math #Коля, привет!
n=int(input())
for i in range(n):
    if i%2:print(" ".join(map(str,[2**j*4**(i//2) for j in range(n)])))
    else:print(" ".join(map(str,[0 for j in range(n)])))
for i in range(int(input())):
    path,x,y,k=[(n-1,n-1)],n-1,n-1,int(input())
    bitmask=list(reversed(list(map(lambda a:bool(int(a)),str(bin(k)[2:])))))+[False for j in range(2*n)]
    for j in range(2*(n-1)):
        if all([x,y]):
            if y%2:
                if bitmask[round(y/2)+x-1]:x-=1
                else:y-=1
            else:
                if bitmask[(y//2)+x-1]:y-=1
                else:x-=1
        else:
            if not x:y-=1
            else:x-=1
        path.insert(0,(x,y))
    for coords in path:print(" ".join(map(lambda a:str(a+1),reversed(coords))));sys.stdout.flush()


import sys,math #Коля, привет!
n=int(input())
for i in range(n):
    if i%2:print(" ".join(map(str,[2**j*4**(i//2) for j in range(n)])))
    else:print(" ".join(map(str,[0 for j in range(n)])))
for i in range(int(input())):
    path,x,y,k=[(n-1,n-1)],n-1,n-1,int(input())
    bitmask=list(reversed(list(map(lambda a:bool(int(a)),str(bin(k)[2:])))))+[False for j in range(2*n)]
    for j in range(2*(n-1)):
        if all([x,y]):
            if y%2:
                if bitmask[y-2+x]:x-=1
                else:y-=1
            else:
                if bitmask[y+x-2]:y-=1
                else:x-=1
        else:
            if not x:y-=1
            else:x-=1
        path.insert(0,(x,y))
    for coords in path:print(" ".join(map(lambda a:str(a+1),reversed(coords))));sys.stdout.flush()


import sys,math #Коля, привет!
n,field=int(input()),[]
for i in range(n):
    if i%2:field.append([2**j*4**(i//2) for j in range(n)])
    else:field.append([0 for j in range(n)])
for row in field:print(" ".join(map(str,row)))
for i in range(int(input())):
    path,x,y,k=[(3,3)],n-1,n-1,int(input())
    bitmask=list(reversed(list(map(lambda a:bool(int(a)),str(bin(k)[2:])))))
    for j in range(2*(n-1)):
        if all((x,y)):
            if y%2:
                if bitmask[int(math.log((field[y][x-1]),2))]:x-=1
                else:y-=1
            else:
                if bitmask[int(math.log((field[y-1][x]),2))]:y-=1
                else:x-=1
        else:
            if not x:y-=1
            else:x-=1
        path.insert(0,(x,y))
    for coords in path:print(" ".join(map(lambda a:str(a+1),reversed(coords))));sys.stdout.flush()


def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def print_list(l):
    print(' '.join(map(str,l)))

n = N()
g = []
for i in range(n):
    if i&1==0:
        g.append([0]*n)
    else:
        s = 1<<(i-1)
        g.append([s<<k for k in range(n)])
for row in g:
    print_list(row)
for _ in range(N()):
    path = N()
    print(1,1)
    f = True
    k = 0
    i,j = 1,1
    for k in range(2*n-2):
        if f:
            if path&(1<<k):
                i+=1
                f = False
            else:
                j+=1
        else:
            if path&(1<<k):
                j+=1
            else:
                i+=1
                f = True
        print(i,j)


import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------------------

def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def print_list(l):
    print(' '.join(map(str,l)))
# import heapq as hq
# import bisect as bs
# from collections import deque as dq
# from collections import defaultdict as dc
# from math import ceil,floor,sqrt
# from collections import Counter

n = N()
g = []
for i in range(n):
    if i&1==0:
        g.append([0]*n)
    else:
        s = 1<<(i-1)
        g.append([s<<k for k in range(n)])
for row in g:
    print_list(row)
for _ in range(N()):
    path = N()
    print(1,1)
    f = True
    k = 0
    i,j = 1,1
    for k in range(2*n-2):
        if f:
            if path&(1<<k):
                i+=1
                f = False
            else:
                j+=1
        else:
            if path&(1<<k):
                j+=1
            else:
                i+=1
                f = True
        print(i,j)


from sys import stdin, stdout

# 0   0   0   0
# 2^3 2^4 2^5 2^6
# 0   0   0   0
# 2^5 2^6 2^7 2^8
#

def construct(n):
    p_a = [[0 for _ in range(n)] for _ in range(n)]
    v = 1 << 3

    for i in range(1, n, 2):
        for j in range(n):
            p_a[i][j] = v
            v = v << 1
        v = v >> (n-2)
    return p_a

def omkar_and_duck(n, p_a, k):

    c = 0
    b = 1 << 3
    for i in range(n//2):
        while k & b == 0:
            stdout.write(str(2*i + 1) + ' ' + str(c + 1) + '\n')

            b = (b << 1)
            c += 1

        stdout.write(str(2 * i + 1) + ' ' + str(c + 1) + '\n')
        stdout.write(str(2 * i + 2) + ' ' + str(c + 1) + '\n')

        while k & (b << 1) == 1:
            c += 1
            stdout.write(str(2 * i + 2) + ' ' + str(c + 1) + '\n')

        b = b << 2

    if n % 2 == 1:
        for i in range(c, n):
            stdout.write(str(n) + ' ' + str(c + 1) + '\n')

    return

n = int(stdin.readline())
p_a = construct(n)
for p in p_a:
    stdout.write(' '.join(map(str, p)) + '\n')
stdout.flush()

q = int(stdin.readline())
for _ in range(q):
    k = int(stdin.readline())
    omkar_and_duck(n, p_a, k)
    stdout.flush()


from sys import stdin, stdout

# 0   0   0   0
# 2^3 2^4 2^5 2^6
# 0   0   0   0
# 2^5 2^6 2^7 2^8
#

def construct(n):
    p_a = [[0 for _ in range(n)] for _ in range(n)]
    v = 1 << 3

    for i in range(1, n, 2):
        for j in range(n):
            p_a[i][j] = v
            v = v << 1
        v = v >> (n-2)
    return p_a

def omkar_and_duck(n, p_a, k):

    c = 0
    b = 1 << 3
    for i in range(n//2):
        while k & b == 0:
            stdout.write(str(2*i + 1) + ' ' + str(c + 1) + '\n')

            b = (b << 1)
            c += 1
        stdout.write(str(2 * i + 1) + ' ' + str(c + 1) + '\n')
        stdout.write(str(2 * i + 2) + ' ' + str(c + 1) + '\n')

        b = b << 2

    if n % 2 == 1:
        for i in range(c, n):
            stdout.write(str(n) + ' ' + str(c + 1) + '\n')

    return

n = int(stdin.readline())
p_a = construct(n)
for p in p_a:
    stdout.write(' '.join(map(str, p)) + '\n')
stdout.flush()

q = int(stdin.readline())
for _ in range(q):
    k = int(stdin.readline())
    omkar_and_duck(n, p_a, k)
    stdout.flush()


from sys import stdin, stdout

# 0   0   0   0
# 2^3 2^4 2^5 2^6
# 0   0   0   0
# 2^5 2^6 2^7 2^8
#

def construct(n):
    p_a = [[0 for _ in range(n)] for _ in range(n)]
    v = 1 << 3

    for i in range(1, n, 2):
        for j in range(n):
            p_a[i][j] = v
            v = v << 1
        v = v >> (n-2)
    return p_a

def omkar_and_duck(n, p_a, k):

    c = 0
    b = 1 << 3
    for i in range(n//2):
        while k & b == 0:
            stdout.write(str(2*i + 1) + ' ' + str(c + 1) + '\n')

            b = b << 1
            c += 1

        stdout.write(str(2 * i + 1) + ' ' + str(c + 1) + '\n')
        stdout.write(str(2 * i + 2) + ' ' + str(c + 1) + '\n')

        while k & (b << 1) != 0:
            c += 1
            stdout.write(str(2 * i + 2) + ' ' + str(c + 1) + '\n')
            b = b << 1

        b = b << 2

    if n % 2 == 1:
        for i in range(c, n):
            stdout.write(str(n) + ' ' + str(c + 1) + '\n')

    return

n = int(stdin.readline())
p_a = construct(n)
for p in p_a:
    stdout.write(' '.join(map(str, p)) + '\n')
stdout.flush()

q = int(stdin.readline())
for _ in range(q):
    k = int(stdin.readline())
    omkar_and_duck(n, p_a, k)
    stdout.flush()