#pragma comment(linker, "/stack:252457298")
#pragma GCC optimize("Ofast")

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

#define endl '\n'
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());

vector<int> x(667), y(667);
vector<int> rowrook(1001, 0), colrook(1001, 0);
vector<vector<bool>> occ(1001, vector<bool>(1001, false));

bool meetMiddle = false;

void Input() {
	for (int i=0; i<667; i++) {
		cin >> x[i] >> y[i];
		if (i == 0) continue;
		rowrook[x[i]]++; colrook[y[i]]++;
		occ[x[i]][y[i]] = true;
	}
}

void Solve() {
	int NW = 0, NE = 0, SW = 0, SE = 0;
	bool goNW = false, goNE = false, goSW = false, goSE = false;

	while (true) {
		for (int i=-1; i<=1; i++) {
			for (int j=-1; j<=1; j++) {
				if (i == 0 && j == 0) continue;
				if (x[0]+i < 1 || x[0]+i > 999) continue;
				if (y[0]+j < 1 || y[0]+j > 999) continue;
				if (occ[x[0]+i][y[0]+j]) continue;
				if (rowrook[x[0]+i] || colrook[y[0]+j]) {
					cout << x[0]+i << " " << y[0]+j << endl;
					fflush(stdout);
					int K, X, Y; cin >> K >> X >> Y;
					if (K == -1) {cerr << "Error found.\n"; return;}
					return;
				}
			}
		}

		if (!meetMiddle && x[0] != 500 && y[0] != 500) {
			if (x[0] < 500 && y[0] < 500) {
				x[0] += 1; y[0] += 1; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] < 500 && y[0] == 500) {
				x[0] += 1; y[0] += 0; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] < 500 && y[0] > 500) {
				x[0] += 1; y[0] -= 1; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] == 500 && y[0] < 500) {
				x[0] += 0; y[0] += 1; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] == 500 && y[0] > 500) {
				x[0] += 0; y[0] -= 1; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] > 500 && y[0] < 500) {
				x[0] -= 1; y[0] += 1; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] > 500 && y[0] == 500) {
				x[0] -= 1; y[0] += 0; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] > 500 && y[0] > 500) {
				x[0] -= 1; y[0] -= 1; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			int K, X, Y; cin >> K >> X >> Y;
			if (K == 0) {cerr << "Error found.\n"; return;}
			if (K == -1 && X == -1 && Y == -1) return;
			occ[x[K]][y[K]] = false; rowrook[x[K]]--; colrook[y[K]]--;
			x[K] = X; y[K] = Y; occ[X][Y] = true; rowrook[X]++; colrook[Y]++;
			continue;
		}

		if (!meetMiddle && x[0] == 500 && y[0] == 500) {
			meetMiddle = true;
			for (int i=1; i<500; i++) {NW += rowrook[i]; NE += rowrook[i]; NW += colrook[i]; SW += colrook[i];}
			for (int i=501; i<1000; i++) {SW += rowrook[i]; SE += rowrook[i]; NE += colrook[i]; SE += colrook[i];}

			if (NW >= NW && NW >= NE && NW >= SW && NW >= SE) goNW = true;
			else if (NE >= NW && NE >= NE && NE >= SW && NE >= SE) goNE = true;
			else if (SW >= NW && SW >= NE && SW >= SW && SW >= SE) goSW = true;
			else if (SE >= NW && SE >= NE && SE >= SW && SE >= SE) goSE = true;
		}

		if (meetMiddle && goNW) {
			x[0]--; y[0]--; cout << x[0] << " " << y[0] << endl; fflush(stdout);
		}

		else if (meetMiddle && goNE) {
			x[0]--; y[0]++; cout << x[0] << " " << y[0] << endl; fflush(stdout);
		}

		else if (meetMiddle && goSW) {
			x[0]++; y[0]--; cout << x[0] << " " << y[0] << endl; fflush(stdout);
		}

		else if (meetMiddle && goSE) {
			x[0]++; y[0]++; cout << x[0] << " " << y[0] << endl; fflush(stdout);
		}

		else {cout << NW << "-" << NE << "-" << SW << "-" << SE << "|" << goNW << goNE << goSW << goSE << endl; fflush(stdout); return;}

			int K, X, Y; cin >> K >> X >> Y;
			if (K == 0) {cerr << "Error found.\n"; return;}
			if (K == -1 && X == -1 && Y == -1) return;
			occ[x[K]][y[K]] = false; rowrook[x[K]]--; colrook[y[K]]--;
			x[K] = X; y[K] = Y; occ[X][Y] = true; rowrook[X]++; colrook[Y]++;
			continue;
	}
}

int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0);
	Input(); Solve(); return 0;
}

/**********************************************\
*  Ngoc-Mai Ngo, #Team4T's Deputy Leader     *
*  #Team4T Secondary Flagship - Destruction  *
\**********************************************/


#pragma comment(linker, "/stack:252457298")
#pragma GCC optimize("Ofast")

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

#define endl '\n'
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());

vector<int> x(667), y(667);
vector<int> rowrook(1001, 0), colrook(1001, 0);
vector<vector<bool>> occ(1001, vector<bool>(1001, false));

bool meetMiddle = false;

void Input() {
	for (int i=0; i<667; i++) {
		cin >> x[i] >> y[i];
		if (i == 0) continue;
		rowrook[x[i]]++; colrook[y[i]]++;
		occ[x[i]][y[i]] = true;
	}
}

void Solve() {
	int NW = 0, NE = 0, SW = 0, SE = 0;
	bool goNW = false, goNE = false, goSW = false, goSE = false;

	while (true) {
		for (int i=-1; i<=1; i++) {
			for (int j=-1; j<=1; j++) {
				if (i == 0 && j == 0) continue;
				if (x[0]+i < 1 || x[0]+i > 999) continue;
				if (y[0]+j < 1 || y[0]+j > 999) continue;
				if (occ[x[0]+i][y[0]+j]) continue;
				if (rowrook[x[0]+i] || colrook[y[0]+j]) {
					cout << x[0]+i << " " << y[0]+j << endl;
					fflush(stdout);
					int K, X, Y; cin >> K >> X >> Y;
					if (K == 0) {cerr << "Error found.\n"; return;}
					if (K == -1 && X == -1 && Y == -1) return;
					occ[x[K]][y[K]] = false; rowrook[x[K]]--; colrook[y[K]]--;
					x[K] = X; y[K] = Y; occ[X][Y] = true; rowrook[X]++; colrook[Y]++;
				}
			}
		}

		if (!meetMiddle && (x[0] != 500 || y[0] != 500)) {
			if (x[0] < 500 && y[0] < 500) {
				x[0] += 1; y[0] += 1; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] < 500 && y[0] == 500) {
				x[0] += 1; y[0] += 0; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] < 500 && y[0] > 500) {
				x[0] += 1; y[0] -= 1; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] == 500 && y[0] < 500) {
				x[0] += 0; y[0] += 1; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] == 500 && y[0] > 500) {
				x[0] += 0; y[0] -= 1; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] > 500 && y[0] < 500) {
				x[0] -= 1; y[0] += 1; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] > 500 && y[0] == 500) {
				x[0] -= 1; y[0] += 0; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			else if (x[0] > 500 && y[0] > 500) {
				x[0] -= 1; y[0] -= 1; cout << x[0] << " " << y[0] << endl; fflush(stdout);
			}

			int K, X, Y; cin >> K >> X >> Y;
			if (K == 0) {cerr << "Error found.\n"; return;}
			if (K == -1 && X == -1 && Y == -1) return;
			occ[x[K]][y[K]] = false; rowrook[x[K]]--; colrook[y[K]]--;
			x[K] = X; y[K] = Y; occ[X][Y] = true; rowrook[X]++; colrook[Y]++;
			continue;
		}

		if (!meetMiddle && x[0] == 500 && y[0] == 500) {
			meetMiddle = true;

			for (int i=1; i<500; i++) {NW += rowrook[i]; NE += rowrook[i]; NW += colrook[i]; SW += colrook[i];}
			for (int i=501; i<1000; i++) {SW += rowrook[i]; SE += rowrook[i]; NE += colrook[i]; SE += colrook[i];}

			if (NW == max({NW, NE, SW, SE})) goNW = true;
			else if (NE == max({NW, NE, SW, SE})) goNE = true;
			else if (SW == max({NW, NE, SW, SE})) goSW = true;
			else if (SE == max({NW, NE, SW, SE})) goSE = true;
		}

		if (meetMiddle && goNW) {
			x[0]--; y[0]--; cout << x[0] << " " << y[0] << endl; fflush(stdout);
		}

		else if (meetMiddle && goNE) {
			x[0]--; y[0]++; cout << x[0] << " " << y[0] << endl; fflush(stdout);
		}

		else if (meetMiddle && goSW) {
			x[0]++; y[0]--; cout << x[0] << " " << y[0] << endl; fflush(stdout);
		}

		else if (meetMiddle && goSE) {
			x[0]++; y[0]++; cout << x[0] << " " << y[0] << endl; fflush(stdout);
		}

		else {cout << NW << "-" << NE << "-" << SW << "-" << SE << "|" << goNW << goNE << goSW << goSE << endl; fflush(stdout); return;}

			int K, X, Y; cin >> K >> X >> Y;
			if (K == 0) {cerr << "Error found.\n"; return;}
			if (K == -1 && X == -1 && Y == -1) return;
			occ[x[K]][y[K]] = false; rowrook[x[K]]--; colrook[y[K]]--;
			x[K] = X; y[K] = Y; occ[X][Y] = true; rowrook[X]++; colrook[Y]++;
			continue;
	}
}

int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0);
	Input(); Solve(); return 0;
}

/**********************************************\
*  Ngoc-Mai Ngo, #Team4T's Deputy Leader     *
*  #Team4T Secondary Flagship - Destruction  *
\**********************************************/


#pragma comment(linker, "/stack:252457298")
#pragma GCC optimize("Ofast")

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

#define endl '\n'
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());

int n, m, u, v, c, ans = 0; vector<int> vis;
vector<vector<pair<int, int>>> adj;

bool DFS_Topo(int z, int last, int lastWeight, set<int> &pendingCycle) {
	vis[z] = 2;

	for (auto Pair: adj[z]) {
		int t = Pair.first, w = Pair.second;
		if (vis[t] == 2) continue;
		if (vis[t] == 1) {
			pendingCycle.insert(t);
			ans = max(ans, w); continue;
		}
		set<int> newSet; DFS_Topo(t, z, w, newSet);
		for (auto it=newSet.begin(); it!=newSet.end(); it++) {
			pendingCycle.insert(*it);
		}
	}

	if (last != -1) {
		ans = max(ans, lastWeight);
	}

	if (pendingCycle.find(last) != pendingCycle.end()) {
		pendingCycle.erase(last);
	}

	vis[z] = 1;
}

void Input() {
	cin >> n >> m; adj.resize(n);
	vis.resize(n, 0);
	while (m--) {
		cin >> u >> v >> c; u--; v--;
		adj[u].push_back({v, c});
	}
}

void Solve() {
	for (int i=0; i<n; i++) {
		if (vis[i] != 0) continue;
		set<int> pendingCycle;
		DFS_Topo(i, -1, -1, pendingCycle);
	}
	cout << ans << endl;
}

int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	Input(); Solve(); return 0;
}

/**********************************************\
*  Ngoc-Mai Ngo, #Team4T's Deputy Leader     *
*  #Team4T Secondary Flagship - Destruction  *
\**********************************************/


#include <bits/stdc++.h>

using namespace std;
int mat[1000][1000];
signed main()
{
#ifdef files
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
    vector<pair<int,int> > v(666);
    int x,y;
    cin >> x >> y;
    for(int i=0; i<666; i++){
        cin >> v[i].first >> v[i].second;
        mat[v[i].first][v[i].second]=1;
    }
    int phase=0;
    int dx,dy;
    while(1){
        if(phase==0){
            if(x>500)dx=-1;
            else if(x<500)dx=1;
            else dx=0;
            if(y>500)dy=-1;
            else if(y<500)dy=1;
            else dy=0;
        }
        if(dx==0 && dy==0){
            phase=1;
            int c1=0, c2=0, c3=0, c4=0;
            for(int i=1; i<500; i++)
                for(int j=1; j<500; j++)c1+=mat[i][j];
            for(int i=1; i<500; i++)
                for(int j=501; j<1000; j++)c2+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=1; j<500; j++)c3+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=501; j<1000; j++)c4+=mat[i][j];
            if(c1<=c2 && c1<=c3 && c1<=c4)dx=-1, dy=-1;
            else if(c2<=c1 && c2<=c3 && c2<=c4)dx=-1, dy=1;
            else if(c3<=c1 && c3<=c2 && c3<=c4)dx=1, dy=-1;
            else dx=1, dy=1;
        }
        if(mat[x+dx][y+dy]){
            cout << x+dx << " " << y << "\n";
            cout.flush();
            return 0;
        }
        cout << x+dx << " " << y+dy << "\n";
        x+=dx;
        y+=dy;
        cout.flush();
        int k, kx, ky;
        cin >> k >> kx >> ky;
        if(k==-1)return 0;
        mat[v[k-1].first][v[k-1].second]=0;
        v[k-1].first=kx;
        v[k-1].second=ky;
        mat[kx][ky]=1;
    }
}


#include <bits/stdc++.h>

using namespace std;
int row[1000];
int col[1000];
int mat[1000][1000];
signed main()
{
#ifdef files
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
    vector<pair<int,int> > v(666);
    int x,y;
    cin >> x >> y;
    int sumx=0, sumy=0;
    for(int i=0; i<666; i++){
        cin >> v[i].first >> v[i].second;
        sumx+=v[i].first;
        sumy+=v[i].second;
        row[v[i].first]=1;
        col[v[i].second]=1;
    }
    while(1){
        if(x>1 && row[x-1]){
            cout << x-1 << " " << y;
            return 0;
        }
        if(x<999 && row[x+1]){
            cout << x+1 << " " << y;
            return 0;
        }
        if(y>1 && col[y-1]){
            cout << x << " " << y-1;
            return 0;
        }
        if(y<999 && col[y+1]){
            cout << x << " " << y+1;
            return 0;
        }
        if(sumx<=x*666){
            if(sumy<=y*666){
                cout << x-1 << " " << y-1 << "\n";
            }
            else{
                cout << x-1 << " " << y+1 << "\n";
            }
        }
        else{
            if(sumy<=y*666){
                cout << x+1 << " " << y-1 << "\n";
            }
            else{
                cout << x+1 << " " << y+1 << "\n";
            }
        }
        cout.flush();
        int k, kx, ky;
        cin >> k >> kx >> ky;
        v[k-1].first=kx;
        v[k-1].second=ky;
        sumx=0;
        sumy=0;
        memset(row,0,sizeof(row));
        memset(col,0,sizeof(col));
        for(int i=0; i<666; i++){
            row[v[i].first]=1;
            col[v[i].second]=1;
            sumx+=v[i].first;
            sumy+=v[i].second;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;
int mat[1000][1000];
signed main()
{
#ifdef files
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
    vector<pair<int,int> > v(666);
    int x,y;
    cin >> x >> y;
    for(int i=0; i<666; i++){
        cin >> v[i].first >> v[i].second;
        mat[v[i].first][v[i].second]=1;
    }
    int phase=0;
    int dx,dy;
    while(1){
        if(phase==0){
            if(x>500)dx=-1;
            else if(x<500)dx=1;
            else dx=0;
            if(y>500)dy=-1;
            else if(y<500)dy=1;
            else dy=0;
        }
        if(dx==0 && dy==0){
            phase=1;
            int c1=0, c2=0, c3=0, c4=0;
            for(int i=1; i<500; i++)
                for(int j=1; j<500; j++)c1+=mat[i][j];
            for(int i=1; i<500; i++)
                for(int j=501; j<1000; j++)c2+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=1; j<500; j++)c3+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=501; j<1000; j++)c4+=mat[i][j];
            if(c1+c4<=c2+c3)dx=-1, dy=-1;
            else dx=1, dy=1;
        }
        if(mat[x+dx][y+dy]){
            cout << x+dx << " " << y << "\n";
            cout.flush();
            return 0;
        }
        cout << x+dx << " " << y+dy << "\n";
        x+=dx;
        y+=dy;
        cout.flush();
        for(int i=0; i<v.size(); i++){
            if(v[i].first==x || v[i].second==y)return 0;
        }
        int k, kx, ky;
        cin >> k >> kx >> ky;
        if(k==-1)return 0;
        mat[v[k-1].first][v[k-1].second]=0;
        v[k-1].first=kx;
        v[k-1].second=ky;
        mat[kx][ky]=1;
    }
}


#include <bits/stdc++.h>

using namespace std;
int mat[1000][1000];
signed main()
{
#ifdef files
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
    vector<pair<int,int> > v(666);
    int x,y;
    cin >> x >> y;
    for(int i=0; i<666; i++){
        cin >> v[i].first >> v[i].second;
        mat[v[i].first][v[i].second]=1;
    }
    int phase=0;
    int dx,dy;
    while(1){
        if(phase==0){
            if(x>500)dx=-1;
            else if(x<500)dx=1;
            else dx=0;
            if(y>500)dy=-1;
            else if(y<500)dy=1;
            else dy=0;
        }
        if(dx==0 && dy==0){
            phase=1;
            int c1=0, c2=0, c3=0, c4=0;
            for(int i=1; i<500; i++)
                for(int j=1; j<500; j++)c1+=mat[i][j];
            for(int i=1; i<500; i++)
                for(int j=501; j<1000; j++)c2+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=1; j<500; j++)c3+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=501; j<1000; j++)c4+=mat[i][j];
            if(c1<=c2 && c1<=c3 && c1<=c4)dx=-1, dy=-1;
            else if(c2<=c1 && c2<=c3 && c2<=c4)dx=-1, dy=1;
            else if(c3<=c1 && c3<=c2 && c3<=c4)dx=1, dy=-1;
            else dx=1, dy=1;
        }
        if(mat[x+dx][y+dy]){
            cout << x+dx << " " << y << "\n";
            cout.flush();
            return 0;
        }
        cout << x+dx << " " << y+dy << "\n";
        cout.flush();
        int k, kx, ky;
        cin >> k >> kx >> ky;
        if(k==-1)return 0;
        mat[v[k-1].first][v[k-1].second]=0;
        v[k-1].first=kx;
        v[k-1].second=ky;
        mat[kx][ky]=1;
    }
}


#include <bits/stdc++.h>

using namespace std;
int mat[1000][1000];
signed main()
{
#ifdef files
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
    vector<pair<int,int> > v(666);
    int x,y;
    cin >> x >> y;
    for(int i=0; i<666; i++){
        cin >> v[i].first >> v[i].second;
        mat[v[i].first][v[i].second]=1;
    }
    int phase=0;
    int dx,dy;
    while(1){
        if(phase==0){
            if(x>500)dx=-1;
            else if(x<500)dx=1;
            else dx=0;
            if(y>500)dy=-1;
            else if(y<500)dy=1;
            else dy=0;
        }
        if(dx==0 && dy==0){
            phase=1;
            int c1=0, c2=0, c3=0, c4=0;
            for(int i=1; i<500; i++)
                for(int j=1; j<500; j++)c1+=mat[i][j];
            for(int i=1; i<500; i++)
                for(int j=501; j<1000; j++)c2+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=1; j<500; j++)c3+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=501; j<1000; j++)c4+=mat[i][j];
            if(c1+c4<=c2+c3)dx=1, dy=1;
            else dx=1, dy=-1;
        }
        if(mat[x+dx][y+dy]){
            cout << x+dx << " " << y << "\n";
            cout.flush();
            return 0;
        }
        cout << x+dx << " " << y+dy << "\n";
        x+=dx;
        y+=dy;
        cout.flush();
        for(int i=0; i<v.size(); i++){
            if(v[i].first==x || v[i].second==y)return 0;
        }
        int k, kx, ky;
        cin >> k >> kx >> ky;
        //k=1, kx=v[0].first, ky=v[0].second;
        if(k==-1)return 0;
        mat[v[k-1].first][v[k-1].second]=0;
        v[k-1].first=kx;
        v[k-1].second=ky;
        mat[kx][ky]=1;
    }
}


#include <bits/stdc++.h>

using namespace std;
int mat[1000][1000];
signed main()
{
#ifdef files
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
    vector<pair<int,int> > v(666);
    int x,y;
    cin >> x >> y;
    for(int i=0; i<666; i++){
        cin >> v[i].first >> v[i].second;
        mat[v[i].first][v[i].second]=1;
    }
    int phase=0;
    int dx,dy;
    while(1){
        if(phase==0){
            if(x>500)dx=-1;
            else if(x<500)dx=1;
            else dx=0;
            if(y>500)dy=-1;
            else if(y<500)dy=1;
            else dy=0;
        }
        if(dx==0 && dy==0){
            phase=1;
            int c1=0, c2=0, c3=0, c4=0;
            for(int i=1; i<500; i++)
                for(int j=1; j<500; j++)c1+=mat[i][j];
            for(int i=1; i<500; i++)
                for(int j=501; j<1000; j++)c2+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=1; j<500; j++)c3+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=501; j<1000; j++)c4+=mat[i][j];
            if(c1+c4<=c2+c3)dx=1, dy=-1;
            else dx=-1, dy=1;
        }
        if(mat[x+dx][y+dy]){
            cout << x+dx << " " << y << "\n";
            cout.flush();
            return 0;
        }
        cout << x+dx << " " << y+dy << "\n";
        x+=dx;
        y+=dy;
        cout.flush();
        for(int i=0; i<v.size(); i++){
            if(v[i].first==x || v[i].second==y)return 0;
        }
        int k, kx, ky;
        cin >> k >> kx >> ky;
        if(k==-1)return 0;
        mat[v[k-1].first][v[k-1].second]=0;
        v[k-1].first=kx;
        v[k-1].second=ky;
        mat[kx][ky]=1;
    }
}


#include <bits/stdc++.h>

using namespace std;
int mat[1000][1000];
signed main()
{
#ifdef files
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
    vector<pair<int,int> > v(666);
    int x,y;
    cin >> x >> y;
    for(int i=0; i<666; i++){
        cin >> v[i].first >> v[i].second;
        mat[v[i].first][v[i].second]=1;
    }
    int phase=0;
    int dx,dy;
    while(1){
        if(phase==0){
            if(x>500)dx=-1;
            else if(x<500)dx=1;
            else dx=0;
            if(y>500)dy=-1;
            else if(y<500)dy=1;
            else dy=0;
        }
        if(dx==0 && dy==0){
            phase=1;
            int c1=0, c2=0, c3=0, c4=0;
            for(int i=1; i<500; i++)
                for(int j=1; j<500; j++)c1+=mat[i][j];
            for(int i=1; i<500; i++)
                for(int j=501; j<1000; j++)c2+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=1; j<500; j++)c3+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=501; j<1000; j++)c4+=mat[i][j];
            if(c1+c4<=c2+c2)dx=1, dy=-1;
            else dx=-1, dy=1;
        }
        if(mat[x+dx][y+dy]){
            cout << x+dx << " " << y << "\n";
            cout.flush();
            return 0;
        }
        cout << x+dx << " " << y+dy << "\n";
        x+=dx;
        y+=dy;
        cout.flush();
        for(int i=0; i<v.size(); i++){
            if(v[i].first==x || v[i].second==y)return 0;
        }
        int k, kx, ky;
        cin >> k >> kx >> ky;
        if(k==-1)return 0;
        mat[v[k-1].first][v[k-1].second]=0;
        v[k-1].first=kx;
        v[k-1].second=ky;
        mat[kx][ky]=1;
    }
}


#include <bits/stdc++.h>

using namespace std;
int mat[1000][1000];
signed main()
{
#ifdef files
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
    vector<pair<int,int> > v(666);
    int x,y;
    cin >> x >> y;
    for(int i=0; i<666; i++){
        cin >> v[i].first >> v[i].second;
        mat[v[i].first][v[i].second]=1;
    }
    int phase=0;
    int dx,dy;
    while(1){
        if(phase==0){
            if(x>500)dx=-1;
            else if(x<500)dx=1;
            else dx=0;
            if(y>500)dy=-1;
            else if(y<500)dy=1;
            else dy=0;
        }
        if(dx==0 && dy==0){
            phase=1;
            int c1=0, c2=0, c3=0, c4=0;
            for(int i=1; i<500; i++)
                for(int j=1; j<500; j++)c1+=mat[i][j];
            for(int i=1; i<500; i++)
                for(int j=501; j<1000; j++)c2+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=1; j<500; j++)c3+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=501; j<1000; j++)c4+=mat[i][j];
            if(c1<=c2 && c1<=c3 && c1<=c4)dx=-1, dy=-1;
            else if(c2<=c1 && c2<=c3 && c2<=c4)dx=-1, dy=1;
            else if(c3<=c1 && c3<=c2 && c3<=c4)dx=1, dy=-1;
            else dx=1, dy=1;
        }
        if(mat[x+dx][y+dy]){
            cout << x+dx << " " << y << "\n";
            cout.flush();
            return 0;
        }
        cout << x+dx << " " << y+dy << "\n";
        cout.flush();
        int k, kx, ky;
        cin >> k >> kx >> ky;
        mat[v[k-1].first][v[k-1].second]=0;
        v[k-1].first=kx;
        v[k-1].second=ky;
        mat[kx][ky]=1;
    }
}


#include <bits/stdc++.h>

using namespace std;
int row[1000];
int col[1000];
int mat[1000][1000];
signed main()
{
#ifdef files
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    vector<pair<int,int> > v(666);
    int x,y;
    cin >> x >> y;
    int sumx=0, sumy=0;
    for(int i=0; i<666; i++){
        cin >> v[i].first >> v[i].second;
        sumx+=v[i].first;
        sumy+=v[i].second;
        row[v[i].first]=1;
        col[v[i].second]=1;
    }
    while(1){
        if(x>1 && row[x-1]){
            cout << x-1 << " " << y;
            return 0;
        }
        if(x<999 && row[x+1]){
            cout << x+1 << " " << y;
            return 0;
        }
        if(y>1 && col[y-1]){
            cout << x << " " << y-1;
            return 0;
        }
        if(y<999 && col[y+1]){
            cout << x << " " << y+1;
            return 0;
        }
        if(sumx<=x*666){
            if(sumy<=y*666){
                cout << x-1 << " " << y-1 << "\n";
            }
            else{
                cout << x-1 << " " << y+1 << "\n";
            }
        }
        else{
            if(sumy<=y*666){
                cout << x+1 << " " << y-1 << "\n";
            }
            else{
                cout << x+1 << " " << y+1 << "\n";
            }
        }
        cout.flush();
        int k, kx, ky;
        cin >> k >> kx >> ky;
        v[k-1].first=kx;
        v[k-1].second=ky;
        sumx=0;
        sumy=0;
        memset(row,0,sizeof(row));
        memset(col,0,sizeof(col));
        for(int i=0; i<666; i++){
            row[v[i].first]=1;
            col[v[i].second]=1;
            sumx+=v[i].first;
            sumy+=v[i].second;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;
int mat[1000][1000];
signed main()
{
#ifdef files
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
    vector<pair<int,int> > v(666);
    int x,y;
    cin >> x >> y;
    for(int i=0; i<666; i++){
        cin >> v[i].first >> v[i].second;
        mat[v[i].first][v[i].second]=1;
    }
    int phase=0;
    int dx,dy;
    while(1){
        if(phase==0){
            if(x>500)dx=-1;
            else if(x<500)dx=1;
            else dx=0;
            if(y>500)dy=-1;
            else if(y<500)dy=1;
            else dy=0;
        }
        if(dx==0 && dy==0){
            phase=1;
            int c1=0, c2=0, c3=0, c4=0;
            for(int i=1; i<500; i++)
                for(int j=1; j<500; j++)c1+=mat[i][j];
            for(int i=1; i<500; i++)
                for(int j=501; j<1000; j++)c2+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=1; j<500; j++)c3+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=501; j<1000; j++)c4+=mat[i][j];
            if(c1<=c2 && c1<=c3 && c1<=c4)dx=-1, dy=-1;
            else if(c2<=c1 && c2<=c3 && c2<=c4)dx=-1, dy=1;
            else if(c3<=c1 && c3<=c2 && c3<=c4)dx=1, dy=-1;
            else dx=1, dy=1;
        }
        if(mat[x+dx][y+dy]){
            cout << x+dx << " " << y << "\n";
            cout.flush();
            return 0;
        }
        cout << x+dx << " " << y+dy << "\n";
        x+=dx;
        y+=dy;
        cout.flush();
        for(int i=0; i<v.size(); i++){
            if(v[i].first==x || v[i].second==y)return 0;
        }
        int k, kx, ky;
        cin >> k >> kx >> ky;
        if(k==-1)return 0;
        mat[v[k-1].first][v[k-1].second]=0;
        v[k-1].first=kx;
        v[k-1].second=ky;
        mat[kx][ky]=1;
    }
}


#include <bits/stdc++.h>

using namespace std;
int mat[1000][1000];
signed main()
{
#ifdef files
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
    vector<pair<int,int> > v(666);
    int x,y;
    cin >> x >> y;
    for(int i=0; i<666; i++){
        cin >> v[i].first >> v[i].second;
        mat[v[i].first][v[i].second]=1;
    }
    int phase=0;
    int dx,dy;
    while(1){
        if(phase==0){
            if(x>500)dx=-1;
            else if(x<500)dx=1;
            else dx=0;
            if(y>500)dy=-1;
            else if(y<500)dy=1;
            else dy=0;
        }
        if(dx==0 && dy==0){
            phase=1;
            int c1=0, c2=0, c3=0, c4=0;
            for(int i=1; i<500; i++)
                for(int j=1; j<500; j++)c1+=mat[i][j];
            for(int i=1; i<500; i++)
                for(int j=501; j<1000; j++)c2+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=1; j<500; j++)c3+=mat[i][j];
            for(int i=501; i<1000; i++)
                for(int j=501; j<1000; j++)c4+=mat[i][j];
            if(c1<=c2 && c1<=c3 && c1<=c4)dx=1, dy=1;
            else if(c2<=c1 && c2<=c3 && c2<=c4)dx=1, dy=-1;
            else if(c3<=c1 && c3<=c2 && c3<=c4)dx=-1, dy=1;
            else dx=-1, dy=-1;
        }
        if(mat[x+dx][y+dy]){
            cout << x+dx << " " << y << "\n";
            cout.flush();
            return 0;
        }
        cout << x+dx << " " << y+dy << "\n";
        x+=dx;
        y+=dy;
        cout.flush();
        for(int i=0; i<v.size(); i++){
            if(v[i].first==x || v[i].second==y)return 0;
        }
        int k, kx, ky;
        cin >> k >> kx >> ky;
        //k=1, kx=v[0].first, ky=v[0].second;
        if(k==-1)return 0;
        mat[v[k-1].first][v[k-1].second]=0;
        v[k-1].first=kx;
        v[k-1].second=ky;
        mat[kx][ky]=1;
    }
}


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

int pos[700][2];
int x, y;

void get() {
	int a, b, c;
	cin >> a >> b >> c;
	if(a==-1) exit(0);
	if(a==0) exit(0);
	pos[a][0] = b;
	pos[a][1] = c;
}

int ab, be, le, ri;
void check() {
	ab=be=le=ri=0;
	for(int i = 1; i <= 666; i++) {
		if(pos[i][0] < x) le++;
		else ri++;
		if(pos[i][1] < x) ab++;
		else be++;
	}
}

signed main() {
	cin >> x >> y;
	for(int i = 1; i <= 666; i++) {
		cin >> pos[i][0] >> pos[i][1];
	}

	for(int move = 0; move < 2000; move++) {
		check();
		if(le > ri) x--;
		else if(le < ri) x++;
		if(ab > be) y--;
		else if(ab < be) y++;
		cout << x << " " << y << endl;

		get();
	}
}


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

int pos[700][2];
int x, y;

void get() {
	int a, b, c;
	cin >> a >> b >> c;
	if(a==-1) exit(0);
	if(a==0) exit(0);
	pos[a][0] = b;
	pos[a][1] = c;
}

int ab, be, le, ri;
void check() {
	ab=be=le=ri=0;
	for(int i = 1; i <= 666; i++) {
		if(pos[i][0] < x) le++;
		else ri++;
		if(pos[i][1] < y) ab++;
		else be++;
	}
}

signed main() {
	cin >> x >> y;
	for(int i = 1; i <= 666; i++) {
		cin >> pos[i][0] >> pos[i][1];
	}

	while(x != 500 && y != 500) {
		if(x > 500) x--;
		else if(x < 500) x++;
		if(y > 500) y--;
		else if(y < 500) y++;
		cout << x << " " << y << endl;
		get();
	}

	check();
	int gx = 1;
	if(le < ri) gx = 999;
	int gy = 1;
	if(ab < be) gy = 999;

	while(x != gx && y != gy) {
		if(x > gx) x--;
		else if(x < gx) x++;
		int ym = 0;
		if(y > gy) y--, ym = 1;
		else if(y < gy) y++;
		bool ok = 1;
		for(int i = 1; i <= 666; i++)
			if(pos[i][0]==x && pos[i][1]==y)
				ok = 0;
		if(ok == 0) {
			if(ym) y++;
			else y--;
		}
		cout << x << " " << y << endl;
		get();
	}
}


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

int pos[700][2];
int x, y;

void get() {
	int a, b, c;
	cin >> a >> b >> c;
	if(a==-1) exit(0);
	if(a==0) exit(0);
	pos[a][0] = b;
	pos[a][1] = c;
}

int ab, be, le, ri;
void check() {
	ab=be=le=ri=0;
	for(int i = 1; i <= 666; i++) {
		if(pos[i][0] < x) le++
		else ri++;
		if(pos[i][1] < x) ab++;
		else be++;
	}
}

signed main() {
	cin >> x >> y;
	for(int i = 1; i <= 666; i++) {
		cin >> pos[i][0] >> pos[i][1];
	}

	for(int move = 0; move < 2000; move++) {
		check();
		if(le > ri) x--;
		else if(le < ri) x++;
		if(ab > be) y--;
		else if(ab < be) y++;
		cout << x << " " << y << endl;

		get();
	}
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
	bool operator<(const Pos &other) const {
		int diff = x - other.x;
		if (!diff)
			diff = y - other.y;
		return diff < 0;
	}
	bool operator==(const Pos &other) const {
		return x == other.x && y == other.y;
	}
	bool operator!=(const Pos &other) const {
		return !(*this == other);
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

bool occupied(const Pos &pos) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i] == pos)
			return true;
	return false;
}

void Move1(Pos dest) {
	if (occupied(dest))
		dest.x = me.x;

	assert(!occupied(dest));
	assert(dist(me, dest) == 1);

	cout << dest.x << ' ' << dest.y << endl;
	me = dest;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0)
		exit(0);
	rooks[k].x = x;
	rooks[k].y = y;
}

void Move(const Pos dest) {
	while (me != dest)
		Move1(me + (dest - me).normalize());
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}

	for (auto &&e : mp)
		if (e.second <= 666 / 4) {
			const Pos dest = { 1000 - e.first.x, 1000 - e.first.y };
			move(dest);
			break;
		}

	// assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
	bool operator<(const Pos &other) const {
		int diff = x - other.x;
		if (!diff)
			diff = y - other.y;
		return diff < 0;
	}
	bool operator==(const Pos &other) const {
		return x == other.x && y == other.y;
	}
	bool operator!=(const Pos &other) const {
		return !(*this == other);
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

bool occupied(const Pos &pos) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i] == pos)
			return true;
	return pos == me;
}

void Move1(Pos dest) {
	assert(dist(me, dest) == 1);

	if (occupied(dest))
		dest.x = me.x;

	assert(!occupied(dest));
	assert(dist(me, dest) == 1);

	cout << dest.x << ' ' << dest.y << endl;
	me = dest;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0) {
		assert(k == -1 || k == 0);
		assert(x == k && y == k);
		exit(0);
	} else {
		assert(1 <= k && k <= 666);
		assert(1 <= x && x <= 999);
		assert(1 <= y && y <= 999);
		rooks[k] = {x, y};
	}
}

void Move(const Pos dest) {
	while (me != dest)
		Move1(me + (dest - me).normalize());
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}
	assert(mp.size() <= 4);

	for (auto &&e : mp)
		if (e.second <= 166) {
			Move( { 1000 - e.first.x, 1000 - e.first.y });
			cout << "AAA" << endl;
			return 0;
		}

	cout << "BBB" << endl;
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	void normalize() {
		x = max(-1, min(1, x));
		y = max(-1, min(1, y));
	}
	bool operator<(const Pos &other) const {
		return false;
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

void Move1(const Pos dest) {
	cout << dest.x << ' ' << dest.y << endl;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0)
		exit(0);
	rooks[k].x = x;
	rooks[k].y = y;
}

void Move(const Pos dest) {
	while (me.x != dest.x || me.y != dest.y) {
		Pos diff = dest - me;
		diff.normalize();
		Move1(me + diff);
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;
	pair<int, Pos> best;

	for (int i = 1; i <= 666; ++i) {
		Pos closest = corners[0];
		for (Pos &pos : corners)
			if (dist(pos, rooks[i]) < dist(closest, rooks[i]))
				closest = pos;
		++mp[closest];
		best = max(best, { -mp[closest], closest });
	}
	best.second.x = 1000 - best.second.x;
	best.second.y = 1000 - best.second.y;
	move(best.second);
	// assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
	bool operator<(const Pos &other) const {
		int diff = x - other.x;
		if (!diff)
			diff = y - other.y;
		return diff < 0;
	}
	bool operator==(const Pos &other) const {
		return x == other.x && y == other.y;
	}
	bool operator!=(const Pos &other) const {
		return !(*this == other);
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

bool occupied(const Pos &pos) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i] == pos)
			return true;
	return pos == me;
}

void Move1(Pos dest) {
	assert(dist(me, dest) == 1);

	if (occupied(dest))
		dest.x = me.x;

	assert(!occupied(dest));
	assert(dist(me, dest) == 1);

	cout << dest.x << ' ' << dest.y << endl;
	me = dest;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0) {
		assert(k == -1 || k == 0);
		assert(x == k && y == k);
		exit(0);
	} else {
		assert(1 <= k && k <= 666);
		assert(1 <= x && x <= 999);
		assert(1 <= y && y <= 999);
		rooks[k] = {x, y};
	}
}

void Move(const Pos dest) {
	while (me != dest)
		Move1(me + (dest - me).normalize());
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}
	assert(mp.size() <= 4);

	for (auto &&e : mp)
		if (e.second <= 166) {
			Move( { 1000 - e.first.x, 1000 - e.first.y });
			assert(false);
		}

	assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
	bool operator<(const Pos &other) const {
		int diff = x - other.x;
		if (!diff)
			diff = y - other.y;
		return diff < 0;
	}
	bool operator==(const Pos &other) const {
		return x == other.x && y == other.y;
	}
	bool operator!=(const Pos &other) const {
		return !(*this == other);
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

bool occupied(const Pos &pos) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i] == pos)
			return true;
	return false;
}

void Move1(Pos dest) {
	if (occupied(dest))
		dest.x = me.x;

	assert(!occupied(dest));
	assert(dist(me, dest) == 1);

	cout << dest.x << ' ' << dest.y << endl;
	me = dest;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0) {
		assert(k == -1 || k == 0);
		assert(x == k && y == k);
		exit(0);
	} else {
		assert(1 <= k && k <= 666);
		assert(1 <= x && x <= 999);
		assert(1 <= y && y <= 999);
		rooks[k] = {x, y};
	}
}

void Move(const Pos dest) {
	while (me != dest)
		Move1(me + (dest - me).normalize());
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}

	for (auto &&e : mp)
		if (e.second <= 666 / 4) {
			const Pos dest = { 1000 - e.first.x, 1000 - e.first.y };
			Move(dest);
			assert(false);
		}

	assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
	bool operator<(const Pos &other) const {
		int diff = x - other.x;
		if (!diff)
			diff = y - other.y;
		return diff < 0;
	}
	bool operator==(const Pos &other) const {
		return x == other.x && y == other.y;
	}
	bool operator!=(const Pos &other) const {
		return !(*this == other);
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

bool occupied(const Pos &pos) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i] == pos)
			return true;
	return pos != me;
}

void Move1(Pos dest) {
	assert(dist(me, dest) == 1);

	if (occupied(dest))
		dest.x = me.x;

	assert(!occupied(dest));
	assert(dist(me, dest) == 1);

	cout << dest.x << ' ' << dest.y << endl;
	me = dest;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0) {
		assert(k == -1 || k == 0);
		assert(x == k && y == k);
		exit(0);
	} else {
		assert(1 <= k && k <= 666);
		assert(1 <= x && x <= 999);
		assert(1 <= y && y <= 999);
		rooks[k] = {x, y};
	}
}

void Move(const Pos dest) {
	while (me != dest)
		Move1(me + (dest - me).normalize());
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}
	assert(mp.size() <= 4);

	for (auto &&e : mp)
		if (e.second <= 166) {
			Move( { 1000 - e.first.x, 1000 - e.first.y });
			assert(false);
		}

	assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	void normalize() {
		x = max(-1, min(1, x));
		y = max(-1, min(1, y));
	}
	bool operator<(const Pos &other) const {
		return false;
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

void Move1(const Pos dest) {
	cout << dest.x << ' ' << dest.y << endl;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0)
		exit(0);
	rooks[k].x = x;
	rooks[k].y = y;
}

void Move(const Pos dest) {
	while (me.x != dest.x || me.y != dest.y) {
		Pos diff = dest - me;
		diff.normalize();
		Move(me + diff);
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;
	pair<int, Pos> best;

	for (int i = 1; i <= 666; ++i) {
		Pos closest = corners[0];
		for (Pos &pos : corners)
			if (dist(pos, rooks[i]) < dist(closest, rooks[i]))
				closest = pos;
		++mp[closest];
		best = max(best, { -mp[closest], closest });
	}
	best.second.x = 1000 - best.second.x;
	best.second.y = 1000 - best.second.y;
	move(best.second);
	assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
	bool operator<(const Pos &other) const {
		int diff = x - other.x;
		if (!diff)
			diff = y - other.y;
		return diff < 0;
	}
	bool operator==(const Pos &other) const {
		return x == other.x && y == other.y;
	}
	bool operator!=(const Pos &other) const {
		return !(*this == other);
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

bool occupied(const Pos &pos) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i] == pos)
			return true;
	return pos == me;
}

void Move1(Pos dest) {
	assert(dist(me, dest) == 1);

	if (occupied(dest))
		dest.x = me.x;

	assert(!occupied(dest));
	assert(dist(me, dest) == 1);

	cout << dest.x << ' ' << dest.y << endl;
	me = dest;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0) {
		assert(k == -1 || k == 0);
		assert(x == k && y == k);
		exit(0);
	} else {
		assert(1 <= k && k <= 666);
		assert(1 <= x && x <= 999);
		assert(1 <= y && y <= 999);
		rooks[k] = {x, y};
	}
}

void Move(const Pos dest) {
	while (me != dest)
		Move1(me + (dest - me).normalize());
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (const Pos &p : corners)
		mp[p];

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}
	assert(mp.size() == 4);

	for (auto &&e : mp)
		if (e.second <= 166) {
			Move( { 1000 - e.first.x, 1000 - e.first.y });
			cout << "AAA" << endl;
			return 0;
		}

	cout << "BBB" << endl;
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
	bool operator<(const Pos &other) const {
		int diff = x - other.x;
		if (!diff)
			diff = y - other.y;
		return diff < 0;
	}
	bool operator==(const Pos &other) const {
		return x == other.x && y == other.y;
	}
	bool operator!=(const Pos &other) const {
		return !(*this == other);
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

bool occupied(const Pos &pos) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i] == pos)
			return true;
	return false;
}

void Move1(Pos dest) {
	if (occupied(dest))
		dest.x = me.x;

	assert(!occupied(dest));
	assert(dist(me, dest) == 1);

	cout << dest.x << ' ' << dest.y << endl;
	me = dest;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0) {
		assert(k == -1 || k == 0);
		assert(x == k && y == k);
		exit(0);
	} else {/*
		assert(1 <= k && k <= 666);
		assert(1 <= x && x <= 999);
		assert(1 <= y && y <= 999);*/
		rooks[k] = {x, y};
	}
}

void Move(const Pos dest) {
	while (me != dest)
		Move1(me + (dest - me).normalize());
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}

	for (auto &&e : mp)
		if (e.second <= 666 / 4) {
			const Pos dest = { 1000 - e.first.x, 1000 - e.first.y };
			Move(dest);
			assert(false);
		}

	assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
	bool operator<(const Pos &other) const {
		int diff = x - other.x;
		if (!diff)
			diff = y - other.y;
		return diff < 0;
	}
	bool operator==(const Pos &other) const {
		return x == other.x && y == other.y;
	}
	bool operator!=(const Pos &other) const {
		return !(*this == other);
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

bool occupied(const Pos &pos) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i] == pos)
			return true;
	return false;
}

void Move1(Pos dest) {
	if (occupied(dest))
		dest.x = me.x;

	assert(!occupied(dest));
	assert(dist(me, dest) == 1);

	cout << dest.x << ' ' << dest.y << endl;
	me = dest;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0) {
		assert(k == -1 || k == 0);
		assert(x == k && y == k);
		exit(0);
	}
	assert(1 <= k && k <= 666);
	assert(1 <= x && x <= 999);
	assert(1 <= y && y <= 999);
	rooks[k] = {x, y};
}

void Move(const Pos dest) {
	while (me != dest)
		Move1(me + (dest - me).normalize());
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}

	for (auto &&e : mp)
		if (e.second <= 666 / 4) {
			const Pos dest = { 1000 - e.first.x, 1000 - e.first.y };
			Move(dest);
			break;
		}

	// assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	void normalize() {
		x = max(-1, min(1, x));
		y = max(-1, min(1, y));
	}
	bool operator<(const Pos &other) const {
		return false;
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

void Move1(const Pos dest) {
	cout << dest.x << ' ' << dest.y << endl;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0)
		exit(0);
	rooks[k].x = x;
	rooks[k].y = y;
}

void Move(const Pos dest) {
	while (me.x != dest.x || me.y != dest.y) {
		Pos diff = dest - me;
		diff.normalize();
		Move(me + diff);
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;
	pair<int, Pos> best;

	for (int i = 1; i <= 666; ++i) {
		Pos closest = corners[0];
		for (Pos &pos : corners)
			if (dist(pos, rooks[i]) < dist(closest, rooks[i]))
				closest = pos;
		++mp[closest];
		best = max(best, { -mp[closest], closest });
	}
	best.second.x = 1000 - best.second.x;
	best.second.y = 1000 - best.second.y;
	move(best.second);
	// assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
	bool operator<(const Pos &other) const {
		int diff = x - other.x;
		if (!diff)
			diff = y - other.y;
		return diff < 0;
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

void Move1(Pos dest) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i].x == dest.x && rooks[i].y == dest.y) {
			dest.x = me.x;
			break;
		}

	for (int i = 1; i <= 666; ++i)
		if (rooks[i].x == dest.x && rooks[i].y == dest.y)
			assert(false);

	cout << dest.x << ' ' << dest.y << endl;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0)
		exit(0);
	rooks[k].x = x;
	rooks[k].y = y;
}

void Move(const Pos dest) {
	while (me.x != dest.x || me.y != dest.y) {
		Move1(me + (dest - me).normalize());
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}

	for (auto &&e : mp)
		if (e.second <= 666 / 4) {
			const Pos dest = { 1000 - e.first.x, 1000 - e.first.y };
			move(dest);
			assert(false);
		}

	assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
	bool operator<(const Pos &other) const {
		int diff = x - other.x;
		if (!diff)
			diff = y - other.y;
		return diff < 0;
	}
	bool operator==(const Pos &other) const {
		return x == other.x && y == other.y;
	}
	bool operator!=(const Pos &other) const {
		return !(*this == other);
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

bool occupied(const Pos &pos) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i] == pos)
			return true;
	return false;
}

void Move1(Pos dest) {
	if (occupied(dest))
		dest.x = me.x;

	assert(!occupied(dest));
	assert(dist(me, dest) == 1);

	cout << dest.x << ' ' << dest.y << endl;
	me = dest;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0) {
		assert(k == -1 || k == 0);
		assert(x == k && y == k);
		exit(0);
	} else {
		assert(1 <= k && k <= 666);
		assert(1 <= x && x <= 999);
		assert(1 <= y && y <= 999);
		rooks[k] = {x, y};
	}
}

void Move(const Pos dest) {
	while (me != dest)
		Move1(me + (dest - me).normalize());
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}

	for (auto &&e : mp)
		if (e.second <= 666 / 4) {
			const Pos dest = { 1000 - e.first.x, 1000 - e.first.y };
			Move(dest);
			break;
		}

// assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

void Move1(Pos dest) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i].x == dest.x && rooks[i].y == dest.y) {
			dest.x = me.x;
			break;
		}
	cout << dest.x << ' ' << dest.y << endl;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0)
		exit(0);
	rooks[k].x = x;
	rooks[k].y = y;
}

void Move(const Pos dest) {
	while (me.x != dest.x || me.y != dest.y) {
		Move1(me + (dest - me).normalize());
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}

	for (auto &&e : mp)
		if (e.second <= 666 / 4) {
			const Pos dest = { 1000 - e.first.x, 1000 - e.first.y };
			move(dest);
			assert(false);
		}

	assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
	bool operator<(const Pos &other) const {
		int diff = x - other.x;
		if (!diff)
			diff = y - other.y;
		return diff < 0;
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

void Move1(Pos dest) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i].x == dest.x && rooks[i].y == dest.y) {
			dest.x = me.x;
			break;
		}
	cout << dest.x << ' ' << dest.y << endl;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0)
		exit(0);
	rooks[k].x = x;
	rooks[k].y = y;
}

void Move(const Pos dest) {
	while (me.x != dest.x || me.y != dest.y) {
		Move1(me + (dest - me).normalize());
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}

	for (auto &&e : mp)
		if (e.second <= 666 / 4) {
			const Pos dest = { 1000 - e.first.x, 1000 - e.first.y };
			move(dest);
			assert(false);
		}

	assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	void normalize() {
		x = max(-1, min(1, x));
		y = max(-1, min(1, y));
	}
	bool operator<(const Pos &other) const {
		return false;
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

void Move1(const Pos dest) {
	cout << dest.x << ' ' << dest.y << endl;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0)
		exit(0);
	rooks[k].x = x;
	rooks[k].y = y;
}

void Move(const Pos dest) {
	while (me.x != dest.x || me.y != dest.y) {
		Pos diff = dest - me;
		diff.normalize();
		Move1(me + diff);
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;
	pair<int, Pos> best;

	for (int i = 1; i <= 666; ++i) {
		Pos closest = corners[0];
		for (Pos &pos : corners)
			if (dist(pos, rooks[i]) < dist(closest, rooks[i]))
				closest = pos;
		++mp[closest];
		best = max(best, { -mp[closest], closest });
	}
	best.second.x = 1000 - best.second.x;
	best.second.y = 1000 - best.second.y;
	move(best.second);
	assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
	bool operator<(const Pos &other) const {
		int diff = x - other.x;
		if (!diff)
			diff = y - other.y;
		return diff < 0;
	}
	bool operator==(const Pos &other) const {
		return x == other.x && y == other.y;
	}
	bool operator!=(const Pos &other) const {
		return !(*this == other);
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

bool occupied(const Pos &pos) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i] == pos)
			return true;
	return false;
}

void Move1(Pos dest) {
	if (occupied(dest))
		dest.x = me.x;

	assert(!occupied(dest));
	assert(dist(me, dest) == 1);

	cout << dest.x << ' ' << dest.y << endl;
	me = dest;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0)
		exit(0);
	rooks[k].x = x;
	rooks[k].y = y;
}

void Move(const Pos dest) {
	while (me != dest)
		Move1(me + (dest - me).normalize());
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}

	for (auto &&e : mp)
		if (e.second <= 666 / 4) {
			const Pos dest = { 1000 - e.first.x, 1000 - e.first.y };
			move(dest);
			assert(false);
		}

	assert(false);
	return 0;
}


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

struct Pos {
	int x, y;
	Pos operator+(const Pos &other) const {
		return Pos { x + other.x, y + other.y };
	}
	Pos operator-(const Pos &other) const {
		return Pos { x - other.x, y - other.y };
	}
	Pos normalize() const {
		return Pos { max(-1, min(1, x)), max(-1, min(1, y)) };
	}
	bool operator<(const Pos &other) const {
		int diff = x - other.x;
		if (!diff)
			diff = y - other.y;
		return diff < 0;
	}
	bool operator==(const Pos &other) const {
		return x == other.x && y == other.y;
	}
	bool operator!=(const Pos &other) const {
		return !(*this == other);
	}
};

int dist(Pos p1, Pos p2) {
	return max(abs(p1.x - p2.x), abs(p1.y - p2.y));
}

Pos me;
Pos rooks[700];

bool occupied(const Pos &pos) {
	for (int i = 1; i <= 666; ++i)
		if (rooks[i] == pos)
			return true;
	return pos != me;
}

void Move1(Pos dest) {
	// assert(dist(me, dest) == 1);

	if (occupied(dest))
		dest.x = me.x;

	assert(!occupied(dest));
	assert(dist(me, dest) == 1);

	cout << dest.x << ' ' << dest.y << endl;
	me = dest;

	int k, x, y;
	cin >> k >> x >> y;
	if (k <= 0) {
		assert(k == -1 || k == 0);
		assert(x == k && y == k);
		exit(0);
	} else {
		assert(1 <= k && k <= 666);
		assert(1 <= x && x <= 999);
		assert(1 <= y && y <= 999);
		rooks[k] = {x, y};
	}
}

void Move(const Pos dest) {
	while (me != dest)
		Move1(me + (dest - me).normalize());
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> me.x >> me.y;
	for (int i = 1; i <= 666; ++i)
		cin >> rooks[i].x >> rooks[i].y;

	Move( { 500, 500 });
	vector<Pos> corners = { { 1, 1 }, { 1, 999 }, { 999, 1 }, { 999, 999 } };
	map<Pos, int> mp;

	for (int i = 1; i <= 666; ++i) {
		const Pos closest = *min_element(corners.begin(), corners.end(), [&](const Pos &p1, const Pos &p2) {
			return dist(rooks[i], p1) < dist(rooks[i], p2);
		});
		++mp[closest];
	}
	assert(mp.size() <= 4);

	for (auto &&e : mp)
		if (e.second <= 166) {
			Move( { 1000 - e.first.x, 1000 - e.first.y });
			assert(false);
		}

	assert(false);
	return 0;
}


#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>

#define ll long long
#define ld long double
#define eps 1e-8
#define MOD 1000000007

#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f

// change if necessary
#define MAXN 1000

using namespace std;

int x, y;
int rook[MAXN][MAXN];
array<int, 2> loc[MAXN];
multiset<int> row;
multiset<int> col;

bool ok(int i, int j) {
    return i >= 0 && j >= 0 && i < 999 && j < 999 && !rook[i][j];
}

int main() {
    cin >> x >> y;
    x--; y--;

    for (int i = 0; i < 999; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        rook[a][b] = true;
        row.insert(a);
        col.insert(b);
        loc[i] = {a, b};
    }

    while (x != 499 && y != 499) {
        int nx = x;
        int ny = y;
        if (x < 499) nx++;
        else if (x > 499) nx--;
        if (y < 499) ny++;
        else if (y > 499) ny--;

        int a, b, c;
        if (rook[nx][ny]) {
            for (int i = -1; i < 2; i++) {
                for (int j = -1; j < 2; j++) {
                    if (i != j && ok(x + i, y + j)) {
                        if (row.count(x + i) || col.count(y + i)) {
                            cout << x + i + 1 << ' ' << y + i + 1 << endl;
                            cin >> a >> b >> c;
                            if (a > 0) {
                                cout << "-1 -1 -1" << endl;
                                cin >> a >> b >> c;
                            }
                            return 0;
                        }
                    }
                }
            }
        }

        cout << nx << ' ' << ny << endl;
        cin >> a >> b >> c;
        if (a <= 0) return 0;
        a--; b--; c--;
        auto &[ro, co] = loc[a];
        row.erase(row.find(ro));
        col.erase(col.find(co));
        row.insert(b);
        col.insert(c);
        loc[a] = {b, c};
        rook[ro][co] = false;
        rook[b][c] = true;
    }

    int a = 0;
    int b = 0;
    int c = 0;

    int cnt1 = 0;
    int cnt2 = 0;
    for (int i = 0; i < 499; i++) {
        if (row.count(i)) cnt1++;
        if (col.count(i)) cnt2++;
    }

    while (true) {
        int nx = x;
        int ny = y;
        if (cnt1 < 666 - cnt1) nx++;
        else nx--;
        if (cnt2 < 666 - cnt2) ny++;
        else ny--;

        if (rook[nx][ny]) {
            for (int i = -1; i < 2; i++) {
                for (int j = -1; j < 2; j++) {
                    if (i != j && ok(x + i, y + j)) {
                        if (row.count(x + i) || col.count(y + i)) {
                            cout << x + i + 1 << ' ' << y + i + 1 << endl;
                            cin >> a >> b >> c;
                            if (a > 0) {
                                cout << "-1 -1 -1" << endl;
                                cin >> a >> b >> c;
                            }
                            return 0;
                        }
                    }
                }
            }
        }

        cout << nx << ' ' << ny << endl;
        cin >> a >> b >> c;
        if (a <= 0) return 0;
        a--; b--; c--;
        auto &[ro, co] = loc[a];
        row.erase(row.find(ro));
        col.erase(col.find(co));
        row.insert(b);
        col.insert(c);
        loc[a] = {b, c};
        rook[ro][co] = false;
        rook[b][c] = true;
    }

    return 0;
}


#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>

#define ll long long
#define ld long double
#define eps 1e-8
#define MOD 1000000007

#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f

// change if necessary
#define MAXN 1000

using namespace std;

int x, y;
int rook[MAXN][MAXN];
array<int, 2> loc[MAXN];
multiset<int> row;
multiset<int> col;

bool ok(int i, int j) {
    return i >= 0 && j >= 0 && i < 999 && j < 999 && !rook[i][j];
}

int main() {
    cin >> x >> y;
    x--; y--;

    for (int i = 0; i < 666; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        rook[a][b] = true;
        row.insert(a);
        col.insert(b);
        loc[i] = {a, b};
    }

    while (x != 499 && y != 499) {
        int nx = x;
        int ny = y;
        if (x < 499) nx++;
        else if (x > 499) nx--;
        if (y < 499) ny++;
        else if (y > 499) ny--;

        int a, b, c;
        if (rook[nx][ny]) {
            for (int i = -1; i < 2; i++) {
                for (int j = -1; j < 2; j++) {
                    if (i != j && ok(x + i, y + j)) {
                        if (row.count(x + i) || col.count(y + i)) {
                            cout << x + i + 1 << ' ' << y + i + 1 << endl;
                            cin >> a >> b >> c;
                            if (a > 0) {
                                cout << "-1 -1 -1" << endl;
                                cin >> a >> b >> c;
                            }
                            return 0;
                        }
                    }
                }
            }
        }

        cout << nx + 1 << ' ' << ny + 1 << endl;
        x = nx;
        y = ny;
        cin >> a >> b >> c;
        if (a <= 0) return 0;
        a--; b--; c--;
        auto &[ro, co] = loc[a];
        row.erase(row.find(ro));
        col.erase(col.find(co));
        row.insert(b);
        col.insert(c);
        loc[a] = {b, c};
        rook[ro][co] = false;
        rook[b][c] = true;
    }

    int a = 0;
    int b = 0;
    int c = 0;

    int cnt1 = 0;
    int cnt2 = 0;
    for (int i = 0; i < 499; i++) {
        if (row.count(i)) cnt1++;
        if (col.count(i)) cnt2++;
    }

    while (true) {
        int nx = x;
        int ny = y;
        if (cnt1 < 666 - cnt1) nx++;
        else nx--;
        if (cnt2 < 666 - cnt2) ny++;
        else ny--;

        if (rook[nx][ny]) {
            for (int i = -1; i < 2; i++) {
                for (int j = -1; j < 2; j++) {
                    if (i != j && ok(x + i, y + j)) {
                        if (row.count(x + i) || col.count(y + i)) {
                            cout << x + i + 1 << ' ' << y + i + 1 << endl;
                            cin >> a >> b >> c;
                            if (a > 0) {
                                cout << "-1 -1 -1" << endl;
                                cin >> a >> b >> c;
                            }
                            return 0;
                        }
                    }
                }
            }
        }

        cout << nx + 1 << ' ' << ny + 1 << endl;
        x = nx;
        y = ny;
        cin >> a >> b >> c;
        if (a <= 0) return 0;
        a--; b--; c--;
        auto &[ro, co] = loc[a];
        row.erase(row.find(ro));
        col.erase(col.find(co));
        row.insert(b);
        col.insert(c);
        loc[a] = {b, c};
        rook[ro][co] = false;
        rook[b][c] = true;
    }

    return 0;
}


/**
 *
 * @author Soroor
 */
import java.util.Scanner;

public class BoysAndGirls {

    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);

            int n,m;
            String s="";
            n=input.nextInt();
            m=input.nextInt();
                for(int i=0; i<m; i++)
                    s+="BG";
            if(n>m)
            {
                for(int i=0;i<n-m; i++)
                    s+="B";

            }
            else
            {
                for(int i=0 ;i<m-n; i++ )
                        s+="G";
            }
            System.out.println(s);
    }

}


import java.util.Scanner;

public class BoysAndGirls {

    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);

            int n,m;
            String s="";
            n=input.nextInt();
            m=input.nextInt();
            if(n>m)
            {
                for(int i=0; i<n; i++)
                {
                    s+="B";
                    if(m!=0)
                    {
                        s+="G";
                        m--;
                    }
                }
            }
            else
            {
                for(int i=0; i<m; i++)
                {
                    s+="G";
                    if(n!=0)
                    {
                        s+="B";
                        n--;
                    }
                }
            }
            System.out.println(s);
    }

}


import java.util.Scanner;

public class BoysAndGirls {

    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);

            int n,m;
            String s="";
            n=input.nextInt();
            m=input.nextInt();
            if(n>m)
            {
                for(int i=0; i<m; i++)
                    s+="BG";
                for(int i=0;i<n-m; i++)
                    s+="B";

            }
            else
            {
                for(int i=0; i<m; i++)
                    s+="GB";
                for(int i=0 ;i<m-n; i++ )
                        s+="G";
            }
            System.out.println(s);
    }

}


import java.util.Scanner;
import java.io.*;

public class BoysAndGirls {

    public static void main(String[] args) throws Exception {

        //Scanner input = new Scanner(System.in);
        Scanner input = new Scanner(new File("input.txt"));
        PrintStream output = new PrintStream("output.txt");
        String s = "";
        int n = input.nextInt();
        int m = input.nextInt();
        for (int i = 0; i < Math.min(n, m); i++) {
            s += (n <= m) ? "GB" : "BG";
        }
        for (int x = 0; x < Math.max(n, m) - Math.min(n, m); x++) {
            s += (n < m) ? "G" : "B";
        }
        output.println(s);
        //System.out.println(s);
    }

}


import java.util.Scanner;

public class BoysAndGirls {

    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);

            String s="";
            int n=input.nextInt();
            int m=input.nextInt();
                for(int i=0; i<Math.min(n, m); i++)
                    s+=(n<=m)?"GB":"BG";
                for(int x=0 ;x<Math.max(n, m)-Math.min(n, m); x++ )
                        s+=(n<m)?"G":"B";
            System.out.println(s);
    }

}


import java.util.Scanner;

public class BoysAndGirls {

    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);

            int n,m;
            String s="";
            String [] a=input.nextLine().split(" ");
            n=Integer.parseInt(a[0]);
            m=Integer.parseInt(a[1]);
                for(int i=0; i<m; i++)
                    s+="BG";
            if(n>m)
            {
                for(int i=0;i<n-m; i++)
                    s+="B";

            }
            else
            {
                for(int i=0 ;i<m-n; i++ )
                        s+="G";
            }
            System.out.println(s);
    }

}


import java.util.Scanner;
import java.math.MathContext;
public class BoysAndGirls {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int G, B, n;
        String s="";
        B=input.nextInt();
        G=input.nextInt();
        n=Math.min(G, B);
        for(int i=0;i<n;i++)
        {
            if(G>=B)
                s+="GB";
            else
                if(B>G)
                    s+="BG";
        }
        if(B>G)
            for(int i=0;i<B-n;i++)
                s+="B";
        else
            for(int i=0;i<G-n;i++)
                s+="G";
        System.out.println(s);
    }
}


import java.util.Scanner;
import java.math.MathContext;
public class BoysAndGirls {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int G, B, n;
        B=input.nextInt();
        G=input.nextInt();
        n=Math.min(G, B);
        for(int i=0;i<n;i++)
        {
            if(G>=B)
                System.out.print("GB");
            else
                if(B>G)
                    System.out.print("BG");
        }
        if(B>G)
            for(int i=0;i<B-n;i++)
                System.out.print("B");
        else
            for(int i=0;i<G-n;i++)
                System.out.print("G");
      //  System.out.println();
    }
}


/**
 *
 * @author Soroor
 */
import java.util.Scanner;

public class BoysAndGirls {

    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        //while(input.hasNext())
        //{
            int n,m;
            String s="";
            n=input.nextInt();
            m=input.nextInt();
            if(n>m)
            {
                for(int i=0; i<n; i++)
                {
                    s+="B";
                    if(m!=0)
                    {
                        s+="G";
                        m--;
                    }
                }
            }
            else
            {
                for(int i=0; i<m; i++)
                {
                    s+="G";
                    if(n!=0)
                    {
                        s+="B";
                        n--;
                    }
                }
            }
            System.out.println(s);
        //}
    }

}


import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

public class A {

	public static void main(String[] args) throws FileNotFoundException {
		Scanner sc = new Scanner(new File("input.txt"));
		PrintWriter out = new PrintWriter(new File("output.txt"));

		// System.out.println(sc.next());
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();
		if (n > m) {
			int d = n - m;
			for (int i = 0; i < m; i++) {
				out.print("BG");
			}
			for (int j = 0; j < d; j++) {
				out.print("B");
			}
		} else if (m > n) {
			int d = m - n;
			for (int i = 0; i < n; i++) {
				out.print("GB");
			}
			for (int j = 0; j < d; j++) {
				out.print("G");
			}
		} else {
			for (int j = 0; j < n; j++) {
				out.print("GB");
			}
		}
		// out.println();
		// sc.close();
		out.close();
		// System.exit(0);
	}

}


import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		if (n > m) {
			int d = n - m;
			for (int i = 0; i < m; i++) {
				System.out.print("BG");
			}
			for (int j = 0; j < d; j++) {
				System.out.print("B");
			}
		} else if (m > n) {
			int d = m - n;
			for (int i = 0; i < n; i++) {
				System.out.print("GB");
			}
			for (int j = 0; j < d; j++) {
				System.out.print("G");
			}
		} else {
			for (int j = 0; j < n; j++) {
				System.out.print("BG");
			}
		}
		System.out.println();
		sc.close();
		System.exit(0);
	}

}


import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		if (n > m) {
			int d = n - m;
			for (int i = 0; i < m; i++) {
				System.out.print("BG");
			}
			for (int j = 0; j < d; j++) {
				System.out.print("B");
			}
		} else if (m > n) {
			int d = m - n;
			for (int i = 0; i < n; i++) {
				System.out.print("GB");
			}
			for (int j = 0; j < d; j++) {
				System.out.print("G");
			}
		} else {
			for (int j = 0; j < n; j++) {
				System.out.print("BG");
			}
		}
		sc.close();
	}

}


import java.util.Scanner;

public class A {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt();
		if (n > m) {
			int d = n - m;
			for (int i = 0; i < m; i++) {
				System.out.print("BG");
			}
			for (int i = 0; i < d; i++) {
				System.out.print("B");
			}
		} else if (m > n) {
			int d = m - n;
			for (int i = 0; i < n; i++) {
				System.out.print("GB");
			}
			for (int i = 0; i < d; i++) {
				System.out.print("G");
			}
		} else {
			for (int i = 0; i < n; i++) {
				System.out.print("BG");
			}
		}
	}

}


import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

public class A {

	public static void main(String[] args) throws FileNotFoundException {
		Scanner sc = new Scanner("input.txt");
		PrintWriter out = new PrintWriter(new File("output.txt"));

		int n = sc.nextInt();
		int m = sc.nextInt();
		if (n > m) {
			int d = n - m;
			for (int i = 0; i < m; i++) {
				out.print("BG");
			}
			for (int j = 0; j < d; j++) {
				out.print("B");
			}
		} else if (m > n) {
			int d = m - n;
			for (int i = 0; i < n; i++) {
				out.print("GB");
			}
			for (int j = 0; j < d; j++) {
				out.print("G");
			}
		} else {
			for (int j = 0; j < n; j++) {
				out.print("GB");
			}
		}
		out.println();
		sc.close();
		out.close();
		System.exit(0);
	}

}


import java.io.*;
import java.util.Scanner;

public class Task253A {

	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("input.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		Scanner in = new Scanner(inputStream);
		int n = in.nextInt();
		int m = in.nextInt();
		in.close();

		StringBuilder q = new StringBuilder();
		if (n >= m) {
			while (n > 0) {
				q.append('B');
				if (m > 0) { q.append('G'); }
				n--;
				m--;
			}
		} else {
			while (m > 0) {
				q.append('G');
				if (n > 0) { q.append('B'); }
				m--;
				n--;
			}
		}

		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("output.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		PrintWriter out = new PrintWriter(outputStream);

		out.println(q);

		out.close();
	}
}


import java.util.Scanner;
import java.io.*;

public class Boys {

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(new File("input.txt"));
		PrintStream out = new PrintStream("output.txt");
		// PrintStream out = System.out;
		int n = in.nextInt(), m = in.nextInt();
		StringBuilder sb = new StringBuilder();
		int i, j, k;

		if (n == m) {
			for (i=0; i<n; ++i) {
				sb.append('G');
				sb.append('B');
			}
		} else if (n < m) {
			sb.append('G');
			for (i=0; i<n; ++i) {
				sb.append('B');
				sb.append('G');
			}
			m -= (n+1);
			while (m-- > 0)
				sb.append('G');
		} else {
			sb.append('B');
			for (i=0; i<m; ++i) {
				sb.append('G');
				sb.append('B');
			}
			n -= (m+1);
			while (n-- > 0)
				sb.append('B');
		}
		out.println(sb);
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
//		InputStreamReader reader = new InputStreamReader(null, "input.txt");
		BufferedReader in = new BufferedReader(new FileReader("input.txt"));
		BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));

		String[] input = in.readLine().split(" ");
		int b = Integer.parseInt(input[0]), g = Integer.parseInt(input[1]);

		String res = "";
		if (b > g) {
			for (int i = 0; i < b; i++) {
				res += "B";
				if (g > 0) {
					res += "G";
					g--;
				}
			}
		} else if (g > b) {
			for (int i = 0; i < g; i++) {
				res += "G";
				if (b > 0) {
					res += "B";
					b--;
				}
			}
		} else {
			for (int i = 0; i < b; i++) {
				res += "BG";
			}
		}
//		System.out.println(res);
		out.write(res);
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
//		InputStreamReader reader = new InputStreamReader(null, "input.txt");
		BufferedReader in = new BufferedReader(new FileReader("input.txt"));
		BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));

		String[] input = in.readLine().split(" ");
		int b = Integer.parseInt(input[0]), g = Integer.parseInt(input[1]);

		String res = "";
		if (b > g) {
			for (int i = 0; i < b; i++) {
				res += "B";
				if (g > 0) {
					res += "G";
					g--;
				}
			}
		} else if (g > b) {
			for (int i = 0; i < g; i++) {
				res += "G";
				if (b > 0) {
					res += "B";
					b--;
				}
			}
		} else {
			for (int i = 0; i < b; i++) {
				res += "BG";
			}
		}
//		System.out.println(res);
		out.write(res);
		out.close();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in);
		BufferedReader in = new BufferedReader(reader);

		String[] input = in.readLine().split(" ");
		int b = Integer.parseInt(input[0]), g = Integer.parseInt(input[1]);

		String res = "";
		if (b > g) {
			for (int i = 0; i < b; i++) {
				res += "B";
				if (g > 0) {
					res += "G";
					g--;
				}
			}
		} else if (g > b) {
			for (int i = 0; i < g; i++) {
				res += "G";
				if (b > 0) {
					res += "B";
					b--;
				}
			}
		} else {
			for (int i = 0; i < b; i++) {
				res += "BG";
			}
		}
		System.out.println(res);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
//		InputStreamReader reader = new InputStreamReader(System.in);
//		BufferedReader in = new BufferedReader(reader);
//
//		String[] input = in.readLine().split(" ");
//		int b = Integer.parseInt(input[0]), g = Integer.parseInt(input[1]);

		Scanner scanner = new Scanner(System.in);
		int b = scanner.nextInt(), g = scanner.nextInt();

		String res = "";
		if (b > g) {
			for (int i = 0; i < b; i++) {
				res += "B";
				if (g > 0) {
					res += "G";
					g--;
				}
			}
		} else if (g > b) {
			for (int i = 0; i < g; i++) {
				res += "G";
				if (b > 0) {
					res += "B";
					b--;
				}
			}
		} else {
			for (int i = 0; i < b; i++) {
				res += "BG";
			}
		}
		System.out.println(res);
	}
}


import java.util.*;

public class boysandgirls {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int boys = in.nextInt();
            int girls = in.nextInt();
            int c=boys+girls;
            boolean r=false;
            if(girls>boys){
             r = true;
            }

            for (int i = 0; i < c; i++) {
                if (boys > 0 && r == false) {
                    System.out.print("B");
                    boys--;
                    if (girls > 0) {
                        r = true;
                    }
                } else if (girls > 0 && r == true) {
                    System.out.print("G");
                    girls--;
                    if (boys > 0) {
                        r = false;
                    }
                }
            }
            System.out.println();

        }
    }

}


import java.util.*;

public class boysandgirls {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			int boys = in.nextInt();
			int girls = in.nextInt();
			int c=boys+girls;
			boolean r=false;
			if(girls>boys){
			 r = true;
			}

			for (int i = 0; i < c; i++) {
				if (boys > 0 && r == false) {
					System.out.print("B");
					boys--;
					if (girls > 0) {
						r = true;
					}
				} else if (girls > 0 && r == true) {
					System.out.print("G");
					girls--;
					if (boys > 0) {
						r = false;
					}
				}
			}
			System.out.println();

		}
	}

}


import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class boysandgirls {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		Scanner in = new Scanner(new FileReader("input.txt"));
		PrintWriter out = new PrintWriter("output.txt");

		int boys = in.nextInt();
		int girls = in.nextInt();

		int c = boys + girls;
		boolean r = false;
		if (girls > boys) {
			r = true;
		}

		for (int i = 0; i < c; i++) {
			if (boys > 0 && r == false) {
				out.print("B");
				boys--;
				if (girls > 0) {
					r = true;
				}
			} else if (girls > 0 && r == true) {
				out.print("G");

				girls--;
				if (boys > 0) {
					r = false;
				}
			}
		}
		out.println();

		in.close();
		out.close();
	}

}


import java.util.*;

public class boysandgirls {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			int boys = in.nextInt();
			int girls = in.nextInt();
			int c = boys + girls;
			boolean r = false;
			if (girls > boys) {
				r = true;
			}

			for (int i = 0; i < c; i++) {
				if (boys > 0 && r == false) {
					System.out.print("B");
					boys--;
					if (girls > 0) {
						r = true;
					}
				} else if (girls > 0 && r == true) {
					System.out.print("G");
					girls--;
					if (boys > 0) {
						r = false;
					}
				}
			}
			System.out.println();

		}
	}

}


import java.io.*;
import java.util.*;

public class CF154A {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);

		StringTokenizer stringTokenizer;

		String next() throws IOException{
			while(stringTokenizer == null || !stringTokenizer.hasMoreTokens()){
				stringTokenizer = new StringTokenizer(br.readLine());
			}
			return stringTokenizer.nextToken();
		 }
		CF154A() throws IOException{

		 }
		int nextInt() throws IOException{
			 return Integer.parseInt(next());
		 }
		long nextLong() throws IOException{
			 return Long.parseLong(next());
		 }
		void solve() throws IOException{
			//EnterCoder here...
			int boys = nextInt();
			int girls = nextInt();

			if(boys>girls){
				for(int i =0;i<boys;i++){
					System.out.print("B");
					if(i<girls){
						System.out.print("G");
					}
				}
			}else{
				for(int i =0;i<girls;i++){
					System.out.print("G");
					if(i<boys){
						System.out.print("B");
					}
				}
			}

		 }
		public static void main(String[] args) throws IOException{
			 new CF154A().solve();
		 }
}


import java.io.*;
import java.util.*;

public class Main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//PrintWriter pw = new PrintWriter(System.out);

		StringTokenizer stringTokenizer;

		String next() throws IOException{
			while(stringTokenizer == null || !stringTokenizer.hasMoreTokens()){
				stringTokenizer = new StringTokenizer(br.readLine());
			}
			return stringTokenizer.nextToken();
		 }
		Main() throws IOException{

		 }
		int nextInt() throws IOException{
			 return Integer.parseInt(next());
		 }
		long nextLong() throws IOException{
			 return Long.parseLong(next());
		 }
		void solve() throws IOException{
			//EnterCoder here...
			int boys = nextInt();
			int girls = nextInt();

			if(boys>girls){
				for(int i =0;i<boys;i++){
					System.out.print("B");
					if(i<girls){
						System.out.print("G");
					}
				}
			}else{
				for(int i =0;i<girls;i++){
					System.out.print("G");
					if(i<boys){
						System.out.print("B");
					}
				}
			}

		 }
		public static void main(String[] args) throws IOException{
			 new Main().solve();
		 }
}


import java.io.*;
import java.util.*;

public class CF154A {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//PrintWriter pw = new PrintWriter(System.out);

		StringTokenizer stringTokenizer;

		String next() throws IOException{
			while(stringTokenizer == null || !stringTokenizer.hasMoreTokens()){
				stringTokenizer = new StringTokenizer(br.readLine());
			}
			return stringTokenizer.nextToken();
		 }
		CF154A() throws IOException{

		 }
		int nextInt() throws IOException{
			 return Integer.parseInt(next());
		 }
		long nextLong() throws IOException{
			 return Long.parseLong(next());
		 }
		void solve() throws IOException{
			//EnterCoder here...
			int boys = nextInt();
			int girls = nextInt();

			if(boys>girls){
				for(int i =0;i<boys;i++){
					System.out.print("B");
					if(i<girls){
						System.out.print("G");
					}
				}
			}else{
				for(int i =0;i<girls;i++){
					System.out.print("G");
					if(i<boys){
						System.out.print("B");
					}
				}
			}

		 }
		public static void main(String[] args) throws IOException{
			 new CF154A().solve();
		 }
}


import java.io.*;
import java.util.*;

public class Main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);

		StringTokenizer stringTokenizer;

		String next() throws IOException{
			while(stringTokenizer == null || !stringTokenizer.hasMoreTokens()){
				stringTokenizer = new StringTokenizer(br.readLine());
			}
			return stringTokenizer.nextToken();
		 }
		Main() throws IOException{

		 }
		int nextInt() throws IOException{
			 return Integer.parseInt(next());
		 }
		long nextLong() throws IOException{
			 return Long.parseLong(next());
		 }
		void solve() throws IOException{
			//EnterCoder here...
			int boys = nextInt();
			int girls = nextInt();

			if(boys>girls){
				for(int i =0;i<boys;i++){
					System.out.print("B");
					if(i<girls){
						System.out.print("G");
					}
				}
			}else{
				for(int i =0;i<girls;i++){
					System.out.print("G");
					if(i<boys){
						System.out.print("B");
					}
				}
			}

		 }
		public static void main(String[] args) throws IOException{
			 new Main().solve();
		 }
}


import java.io.*;
import java.util.*;

public class CF154A {

		BufferedReader br = new BufferedReader(new FileReader("input.txt"));
		FileWriter writer = new FileWriter(new File("output.txt"));

		StringTokenizer stringTokenizer;

		String next() throws IOException{
			while(stringTokenizer == null || !stringTokenizer.hasMoreTokens()){
				stringTokenizer = new StringTokenizer(br.readLine());
			}
			return stringTokenizer.nextToken();
		 }
		CF154A() throws IOException{

		 }
		int nextInt() throws IOException{
			 return Integer.parseInt(next());
		 }
		long nextLong() throws IOException{
			 return Long.parseLong(next());
		 }
		void solve() throws IOException{
			//EnterCoder here...
			int boys = nextInt();
			int girls = nextInt();
			StringBuilder output = new StringBuilder();

			if(boys>girls){
				for(int i =0;i<boys;i++){
					output.append("B");
					if(i<girls){
						output.append("G");
					}
				}
			}else{
				for(int i =0;i<girls;i++){
					output.append("G");
					if(i<boys){
						output.append("B");
					}
				}
			}
			writer.write(output.toString());
			writer.close();

		 }
		public static void main(String[] args) throws IOException{
			 new CF154A().solve();
		 }
}


import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main
{

    public static void main(String[] args) throws FileNotFoundException
    {
        Scanner sc = new Scanner (new File ("input.txt"));
        PrintWriter pw = new PrintWriter(new File("output.txt"));

        int n = sc.nextInt();
        int m = sc.nextInt();

        boolean boys = false;
        if (n < m)
            boys = true;

        StringBuilder ans = new StringBuilder();
        if (boys)
        {
            for (int i = 0; i < n; ++i)
            {
                ans.append("GB");
                m--;
            }
            for (int i = 0; i < m; ++i)
                ans.append("G");
        }
        else
        {
            for (int i = 0; i < m; ++i)
            {
                ans.append("BG");
                n--;
            }
            for (int i = 0; i < n; ++i)
                ans.append("B");
        }

        pw.println(ans);
        pw.close();
    }
}


import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.util.InputMismatchException;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("input.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("output.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n=in.readInt();
        int m=in.readInt();
        for (;n>0&&m>0;n--,m--){
            String v;
            v= n>m?"BG":"GB";
            out.print(v);
        }
        for (;n>0;n--) out.print("B");
        for (;m>0;m--) out.print("G");
    }
}

class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
                this.stream = stream;
        }

        public int read() {
                if (numChars == -1)
                        throw new InputMismatchException();
                if (curChar >= numChars) {
                        curChar = 0;
                        try {
                                numChars = stream.read(buf);
                        } catch (IOException e) {
                                throw new InputMismatchException();
                        }
                        if (numChars <= 0)
                                return -1;
                }
                return buf[curChar++];
        }

        public int readInt() {
                int c = read();
                while (isSpaceChar(c))
                        c = read();
                int sgn = 1;
                if (c == '-') {
                        sgn = -1;
                        c = read();
                }
                int res = 0;
                do {
                        if (c < '0' || c > '9')
                                throw new InputMismatchException();
                        res *= 10;
                        res += c - '0';
                        c = read();
                } while (!isSpaceChar(c));
                return res * sgn;
        }

        public boolean isSpaceChar(int c) {
                if (filter != null)
                        return filter.isSpaceChar(c);
                return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
                public boolean isSpaceChar(int ch);
        }
}