1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <bits/stdc++.h>
using namespace std;

int n;
int t;
int q;

int r[32];
vector < vector <bool> > poz[32];
vector < vector <bool> > pio[32];

int x, y;
int rx, ry;
int mom;

inline void move()
{
	mom++;
	x+=rx;
	y+=ry;
	if (poz[n][x][y])
		ry*=-1;
	if (pio[n][x][y])
		rx*=-1;
}

int main()
{
	scanf("%d", &n);
	poz[0].resize(5, vector<bool>(5, 0));
	pio[0].resize(5, vector<bool>(5, 0));
	poz[0][1][0]=1;
	poz[0][1][2]=1;
	pio[0][0][1]=1;
	pio[0][2][1]=1;
	
	pio[0][0][0]=poz[0][0][0]=1;
	pio[0][0][2]=poz[0][0][2]=1;
	pio[0][2][0]=poz[0][2][0]=1;
	pio[0][2][2]=poz[0][2][2]=1;
	pio[0][1][1]=poz[0][1][1]=1;
	
	r[0]=2;
	for (int h=1; h<=n; h++)
	{
		r[h]=r[h-1]*2;
		poz[h].resize(r[h]+1, vector<bool>(r[h]+1, 0));
		pio[h].resize(r[h]+1, vector<bool>(r[h]+1, 0));
		
		//lg
		for (int i=1; i<r[h-1]; i++)
		{
			for (int j=1; j<r[h-1]; j++)
			{
				poz[h][i][j+r[h-1]]=poz[h-1][i][j];
				pio[h][i][j+r[h-1]]=pio[h-1][i][j];
			}
		}
		
		//pg
		for (int i=1; i<r[h-1]; i++)
		{
			for (int j=1; j<r[h-1]; j++)
			{
				poz[h][i+r[h-1]][j+r[h-1]]=poz[h-1][i][j];
				pio[h][i+r[h-1]][j+r[h-1]]=pio[h-1][i][j];
			}
		}
		
		//ld
		for (int i=1; i<r[h-1]; i++)
		{
			for (int j=1; j<r[h-1]; j++)
			{
				poz[h][j][r[h-1]-i]=pio[h-1][i][j];
				pio[h][j][r[h-1]-i]=poz[h-1][i][j];
			}
		}
		
		//pd
		for (int i=1; i<r[h-1]; i++)
		{
			for (int j=1; j<r[h-1]; j++)
			{
				poz[h][r[h]-j][r[h-1]-i]=pio[h-1][i][j];
				pio[h][r[h]-j][r[h-1]-i]=poz[h-1][i][j];
			}
		}
		
		pio[h][1][r[h-1]]=1;
		pio[h][r[h]-1][r[h-1]]=1;
		poz[h][r[h-1]][r[h-1]+1]=1;
		
		for (int i=0; i<=r[h]; i++)
		{
			poz[h][i][0]=1;
			poz[h][i][r[h]]=1;
			pio[h][0][i]=1;
			pio[h][r[h]][i]=1;
		}
	}
	x=1;
	y=0;
	rx=1;
	ry=1;
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d", &q);
		while(mom<q)
			move();
		printf("%d %d\n", x, y);
	}
	
	return 0;
}