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

import os
import sys
import math
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

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

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

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

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

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

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

#-------------------game starts now-----------------------------------------------------
n, m = map(int, input().split())
l = set()
s = {i for i in range(1, 101)}
b = False
for i in range(m):
  k, f = map(int, input().split())
  if k == n:
    print(f)
    b = True
    break
  j = 1
  if f == 1:
    l = {i for i in range(k, 101)}
  else:
    while j <= (k-j)//(f-1):
      if (k-j)%(f-1) == 0:
        l.add((k-j)//(f-1))
        j += f-1
      else:
        j += 1
  s &= l
  l.clear()
a = -1
if b == False:
  t = True
  for j in s:
    if a == -1:
      a = (n-1)//j
    else:
      if (n-1)//j != a:
        print(-1)
        t = False
        break
  if t == True:
    print(a+1)


import math
n,q = map(int,input().split())
lst = [ ]

for i in range(q):
	x,y  = map(int,input().split())
	lst.append((x,y))

count =  0
ans	  = -1
for no_of_floors in range(1,101):
	flag = 1
	for k,f in lst:
		k-=1
		temp_floor = math.ceil(k/no_of_floors)
		if(temp_floor!=f):
			flag = 0
	if(flag):
		# print(no_of_floors)
		count+=1
		ans  = math.ceil(n/no_of_floors)

if(count==1):
	print(ans)
else:
	# print(count)
	print(-1)


import math
n,q = map(int,input().split())
lst = [ ]

for i in range(q):
	flat,floor = map(int,input().split())
	lst.append((flat,floor))

lst.sort()

flag = 0
for i in range(1,q):
	if(lst[i-1][0]+1==lst[i][0] and lst[i-1][1]!=lst[i][1]):
		flag = i-1
		break

if(flag!=0):
	no_of_f = lst[flag][0]//lst[flag][1]
	ans 	= math.ceil(n/no_of_f)
	print(ans)
else:
	print(-1)


import math
n,q = map(int,input().split())
lst = [ ]

for i in range(q):
	flat,floor = map(int,input().split())
	lst.append((flat,floor))

lst.sort()

flag = 0
for i in range(1,q):
	if(lst[i-1][0]+1==lst[i][0] and lst[i-1][1]!=lst[i][1]):
		flag = i-1
		break

if(flag!=0):
	no_of_f = lst[flag][0]//lst[flag][1]
	ans 	= math.ceil(n/no_of_f)
	print(n,no_of_f)
	print(ans)
else:
	print(-1)


import math
n,q = map(int,input().split())
lst = [ ]

for i in range(q):
	x,y  = map(int,input().split())
	lst.append((x,y))

ans = set()

for no_of_floors in range(1,101):
	flag = 1
	for k,f in lst:
		temp_floor = math.ceil(k/no_of_floors)
		if(temp_floor!=f):
			flag = 0
	if(flag):
		temp  = math.ceil(n/no_of_floors)
		ans.add(temp)

if(len(ans)!=1):
	print(-1)
else:
	print(*ans)


import math
n,q = map(int,input().split())
lst = [ ]

for i in range(q):
	x,y  = map(int,input().split())
	lst.append((x,y))

count =  0
ans	  = -1
for no_of_floors in range(1,101):
	flag = 1
	for k,f in lst:
		temp_floor = math.ceil(k/no_of_floors)
		if(temp_floor!=f):
			flag = 0
	if(flag):
		count+=1
		ans  = math.ceil(n/no_of_floors)

if(count==1):
	print(ans)
else:
	print(-1)


n, m = map(int, input().split())
k = []
f = []
for _ in range(m):
    a, b = map(int, input().split())
    k.append(a)
    f.append(b)
mb = {i for i in range(1, 105)}
for i in range(m):
    now = set()
    for p in range(1, 105):
        if (k[i] - 1) // p + 1 == f[i]:
            now.add(p)
    mb.intersection_update(now)
can = set()
for x in mb:
    can.add((n - 1) // x + 1)
if len(can) != 1:
    print(-1)
else:
    for x in can:
        print(x)


n, m = map(int, input().split())
k = []
f = []
for _ in range(m):
    a, b = map(int, input().split())
    k.append(a)
    f.append(b)
mb = set()
for i in range(m):
    for p in range(1, 105):
        if (k[i] - 1) // p == f[i]:
            mb.add(p)
can = set()
for x in mb:
    can.add((n - 1) // x)
if len(can) != 1:
    print(-1)
else:
    for x in can:
        print(x)


n, m = map(int, input().split())
k = []
f = []
for _ in range(m):
    a, b = map(int, input().split())
    k.append(a)
    f.append(b)
mb = {i for i in range(1, 105)}
for i in range(m):
    now = set()
    for p in range(1, 105):
        if (k[i] - 1) // p == f[i]:
            now.add(p)
    mb.intersection_update(now)
can = set()
for x in mb:
    can.add((n - 1) // x)
if len(can) != 1:
    print(-1)
else:
    for x in can:
        print(x)


n, m = map(int, input().split())
e = []
for i in range(m):
    e.append(list(map(int,input().split())))
check = False
if m == 0 and n != 1:
    print(-1)
    exit(0)
ans = []
for i in range(1, 101):
    check = True
    for j in range(0, m):
        if (e[j][0] + i - 1) // i != e[j][1]:
            check = False
            break
    if check:
        ans.append(i)
minimum = (n + ans[0] - 1) // ans[0]
check = True
for i in range(1, len(ans)):
    if (n + ans[i] - 1) // ans[i] != minimum:
        check = False
        break
if check:
    print(minimum)
else:
    print(-1)


n, m = map(int, input().split())
e = []
for i in range(m):
    e.append(list(map(int,input().split())))
check = False
if m == 0 and n != 1:
    print(-1)
    exit(0)
ans = []
for i in range(1, 101):
    check = True
    for j in range(0, m):
        if (e[j][0] + i - 1) // i != e[j][1]:
            check = False
            break
    if check:
        ans.append(i)
minimum = (n + ans[0] - 1) // ans[0]
for i in range(1, len(ans)):
    if (n + ans[i] - 1) // ans[i] != minimum:
        check = False
        break
if check:
    print(minimum)
else:
    print(-1)


n, m = list(map(int, input().split()))
l = []
may = []
for i in range(m):
    l.append(list(map(int, input().split())))
g = 0
for i in range(1, 101):
    fl = True
    for j in l:
        a =j[0]
        b =j[1]
        if (a - 1)// i + 1 != b:
            fl =False
            break
    if fl:
        may.append(i)
for i in range(len(may) - 1):
    if (n-1) // may[i] + 1 != (n-1) // may[i+1] + 1:
        print(-1)
        exit()
print((n-1) // may[0] + 1)


n, m = list(map(int, input().split()))
l_t = 0
r_t = float('inf')
for i in range(m):
    a, b = list(map(int, input().split()))
    l = (a - 1)// b + 1
    r = (a - 1) // (b- 1)
    if r < r_t :
        r_t = r
    if l > l_t:
        l_t = l
ansl = (n - 1) // l_t + 1
ansr = (n - 1) // r_t + 1
if ansl != ansr:
    print(-1)
else:
    print(ansl)


from math import ceil
n, m = map(int, input().split())
k = [0] * m
f = [0] * m
p = []
for i in range(m):
    k[i], f[i] = map(int, input().split())
for i in range(1, 101):
    good = True
    for j in range(m):
        if f[j] == ceil(k[j] / i):
            continue
        else:
            good = False
            break
    if good:
        p.append(i)
s = set()
for i in p:
    s.add(n // i + 1)
if len(s) != 1:
    print(-1)
else:
    for i in s:
        print(i)


from math import ceil
n, m = map(int, input().split())
k = [0] * m
f = [0] * m
p = []
for i in range(m):
    k[i], f[i] = map(int, input().split())
for i in range(1, 101):
    good = True
    for j in range(m):
        if f[j] == ceil(k[j] / i):
            continue
        else:
            good = False
            break
    if good:
        p.append(i)
if len(p) != 1:
    print(-1)
else:
    print(n // p[0] + 1)


from math import ceil
n, m = map(int, input().split())
k = [0] * m
f = [0] * m
p = []
for i in range(m):
    k[i], f[i] = map(int, input().split())
for i in range(1, 101):
    good = True
    for j in range(m):
        if f[j] == ceil(k[j] / i):
            continue
        else:
            good = False
            break
    if good:
        p.append(i)
s = set()
for i in p:
    s.add(ceil(n / i))
if len(s) != 1:
    print(-1)
else:
    for i in s:
        print(i)


n, m = map(int, input().split())
k = []
for i in range(m):
    k.append([])
    k[i] = list(map(int, input().split()))
answ = []
for i in range(1,101):
    test = True
    for j in range(m):
        t = (k[j][0]+i-1)//i
        if t != k[j][1]:
            test = False
    if test:
        answ.append(i)
if len(answ) == 0:
    print(-1)
    exit(0)
t = []
for i in answ:
    t.append((n+i-1)//i)
if min(t) != max(t):
    print(-1)
    exit(0)
print(t[0])


n, m = map(int, input().split())
k = []
for i in range(m):
    k.append([])
    k[i] = list(map(int, input().split()))
answ = []
for i in range(1,101):
    test = True
    for j in range(m):
        t = (k[j][0]+i-1)//i
        if t != k[j][1]:
            test = False
    if test:
        answ.append(i)
if len(answ) != 1:
    print(-1)
    exit(0)
print((n+answ[0]-1)//answ[0])


n, m = map(int, input().split())
s = []
otv = set()
for i in range(m):
	z, j = map(int, input().split())
	s.append((z, j))
for i in range(1, 101):
	o = 1
	for z, j in s:
		if (z + i - 1) // i != j:
			o = 0
			break
	if o:
		otv.add((n + i - 1) // i)
if len(otv) == 1:
	print(otv.pop())
else:
	print(-1)


n, m = map(int, input().split())
s = []
otv = set()
for i in range(m):
	z, j = map(int, input().split())
	s.append((z, j))
for i in range(1, 101):
	o = j
	for z, j in s:
		if (z + i - 1) // i != j:
			o = 0
			break
	if o:
		otv.add((n + i - 1) // i)
if len(otv) == 1:
	print(otv.pop())
else:
	print(-1)


n, m1 = map(int, input().split())
ans = set()
a = []
l = 0
for i in range(m1):
	k, f = map(int, input().split())
	a.append((k, f))
for kol in range(1, 101):
	fl = True
	for elem in a:
		k = elem[0]
		f = elem[1]
		if (k + kol - 1) // kol != f:
			fl = False
			break
	if fl:
		ans.add((n + kol - 1) // kol)
if len(ans) != 1:
	print(-1)
	exit()
print(ans.pop())


n, m1 = map(int, input().split())
ans = -1
a = []
l = 0
for i in range(m1):
	k, f = map(int, input().split())
	a.append((k, f))
for kol in range(1, 101):
	fl = True
	for elem in a:
		k = elem[0]
		f = elem[1]
		if (k + kol - 1) // kol != f:
			fl = False
			break
	if fl:
		if ans != -1:
			print(-1)
			exit()
		ans = (kol + n - 1) // kol
print(ans)


import math
n,m = map(int,input().split())
dic = {}
for i in range(1,101):
    dic[i]=[]
for i in range(m):
    k,f = map(int,input().split())
    dic[f].append(k)
ans = []
for f in range(1,101):
    f1 = 0
    for i in dic:
        for j in dic[i]:
            if j>f*(i-1) and j<=f*(i):
                continue
            else:
                f1=1
                break
        if f1==1:
            break
    if f1==0:
        ans.append(f)
if len(ans)==1:
    print(math.ceil(n/ans[0]))
else:
    print(-1)


import math
n,m = map(int,input().split())
dic = {}
for i in range(1,101):
    dic[i]=[]
for i in range(m):
    k,f = map(int,input().split())
    dic[f].append(k)
ans = []
for f in range(1,101):
    f1 = 0
    for i in dic:
        for j in dic[i]:
            if j>f*(i-1) and j<=f*(i):
                continue
            else:
                f1=1
                break
        if f1==1:
            break
    if f1==0:
        ans.append(f)
#print(ans)
if len(ans)>=1:
    p=math.ceil(n/ans[0])
    f=0
    for i in range(len(ans)):
        if math.ceil(n/ans[i])==p:
            continue
        else:
            f=1
            break
    if f==1:
        print(-1)
    else:
        print(p)
else:
    print(-1)


l=[]
f=fn=0
[n,m]=map(int,input().split())
for i in range(m): l.append(list(map(int,input().split())))
for i in range(1,101):
    for j in l:
        if (j[0]//i if j[0]%i==0 else j[0]//i+1)!=j[1]:
            break
    else:
        if f==0:
            f=i
            fn=(n//i if n%i==0 else n//i+1)
        elif fn!=(n//i if n%i==0 else n//i+1):
            print(-1)
            exit()
print(fn)


n, m = [int(i) for i in input().split()]
floor_info = [[int(i) for i in input().split()] for j in range(m)]
ans = list(set([(n-1)// i + 1 for i in range(1,101) if all([(sub_floor[0]-1)// i + 1 == sub_floor[1] for sub_floor in floor_info])]))
if len(ans) == 1:
    print(ans[0])
else:
    print(-1)


from math import ceil

[n, m] = [int(x) for x in input().split()]

possible = [True]*110

flats = []
for i in range(0, m):
    flats.append([int(x) for x in input().split()])

for flat in flats:
    for size in range(1, 101):
        if ceil(flat[0]/size) != flat[1]:
            possible[size] = False

ans = -1
for size in range(1,101):
    if possible[size]:
        possible_floor = ceil(n/size)
        # print(possible_floor)
        if ans == -1:
            ans = possible_floor
        elif ans != possible_floor:
            print(-1)
            exit()
# print(possible)
print(ans)


from math import ceil

[n, m] = [int(x) for x in input().split()]

possible = [True]*110

flats = []
for i in range(0, m):
    flats.append([int(x) for x in input().split()])

for flat in flats:
    for size in range(1, 100):
        if ceil(flat[0]/size) != flat[1]:
            possible[size] = False

ans = -1
for size in range(1,100):
    if possible[size]:
        possible_floor = ceil(n/size)
        if ans == -1:
            ans = possible_floor
        elif ans != possible_floor:
            print(-1)
            exit()
print(ans)


# arr=list(map(int,input().split()))
# arr=sorted([(n-int(x),i) for i,x in enumerate(input().split())])
# arr=[int(q)-1 for q in input().split()]
# from collections import Counter
# n=int(input())
# n,k=map(int,input().split())
# arr=list(map(int,input().split()))
# for i in range(m):
#for _ in range(int(input())):
#n=int(input())
import math
n, m= map(int, input().split())
ls=[]
pos=[]
for i in range(m):
    u,v = map(int, input().split())
    ls.append((u,v))
for i in range(1,101):
    cnt=0
    for j in range(m):
        if math.ceil(ls[j][0]/i)==ls[j][1]:
            cnt+=1
        else:
            break
    if cnt==m:
        pos.append(math.ceil(n/i))

print(pos[0] if len(list(set(pos)))==1 else -1)


# arr=list(map(int,input().split()))
# arr=sorted([(n-int(x),i) for i,x in enumerate(input().split())])
# arr=[int(q)-1 for q in input().split()]
# from collections import Counter
# n=int(input())
# n,k=map(int,input().split())
# arr=list(map(int,input().split()))
# for i in range(m):
#for _ in range(int(input())):
#n=int(input())
import math
n, m= map(int, input().split())
ls=[]
pos=[]
for i in range(m):
    u,v = map(int, input().split())
    ls.append((u,v))
for i in range(1,101):
    cnt=0
    for j in range(m):
        if math.ceil(ls[j][0]/i)==ls[j][1]:
            cnt+=1
        else:
            break
    if cnt==m:
        pos.append(math.ceil(n/i))

print(-1 if len(pos)>1 else pos[0])


n, m = map(int, input().split())
u = []
s = {}
ok = False
for i in range(m):
    u.append(tuple(map(int, input().split())))
    s[u[i][0]] = u[i][1]
    if u[i][0] - 1 in s.keys():
        if s[u[i][0]] != s[u[i][0] - 1]:
            ok = True
            p = u[i][0] - 1
    if u[i][0] + 1 in s.keys():
        if s[u[i][0]] != s[u[i][0] + 1]:
            ok = True
            p = u[i][0]
if not ok:
    print(-1)
    exit()
d = p // s[p]
print((n - 1) // d + 1)


n, m = map(int, input().split())
u = []
ook = True
ans = -1
for i in range(m):
    u.append(tuple(map(int, input().split())))
for cf in range(1, 101):
    ok = True
    for i in range(m):
        if (u[i][0] - 1) // cf + 1 != u[i][1]:
            ok = False
            break
    if ok and ans != -1 and (n - 1) // cf + 1 != ans:
        print(-1)
        ook = False
        break
    elif ok:
        ans = (n - 1) // cf + 1
if ook:
    print(ans)


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n'

const int MOD = 1e9+7; //998244353;
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;

void setIO(const string& s) {
//	ios_base::sync_with_stdio(false);
//	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

pair<int,int> operator+(const pair<int,int>& a, const pair<int,int>& b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

pair<int,int>& operator+=(pair<int,int>& a, const pair<int,int>& b) {
    a.first += b.first, a.second += b.second;
}

int mat[1000][1000];
pair<int,int> rooks[667];

signed main() {
    setIO("input");

    pair<int,int> king;
    cin >> king.first >> king.second;
    for(int i=1; i<=666; ++i) {
        cin >> rooks[i].first >> rooks[i].second;
        ++mat[rooks[i].first][rooks[i].second];
    }

    for(int i=0; i<=1; ++i) {
        int& cur = (i==0?king.first:king.second);
        while(cur != 500) {
                if(cur > 500) --cur;
                else ++cur;
                cout << king.first << ' ' << king.second << endl;
                int id,x,y; cin >> id >> x >> y;
                if(id == -1 && x == -1 && y == -1) {
                    return 0;
                }
                --mat[rooks[id].first][rooks[id].second];
                rooks[id].first = x, rooks[id].second = y;
                ++mat[rooks[id].first][rooks[id].second];
        }
    }

    int quad1 = 0, quad2 = 0, quad3 = 0, quad4 = 0;
    for(int i=1; i<=499; ++i) for(int j=501; j<=999; ++j) quad1 += mat[i][j];
    for(int i=1; i<=499; ++i) for(int j=1; j<=499; ++j) quad2 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=1; j<=499; ++j) quad3 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=501; j<=999; ++j) quad4 += mat[i][j];

    pair<int,int> dir;
    int mn = min({quad1, quad2, quad3, quad4});
    if(mn == quad1) {
        dir = {1, -1};
    } else if(mn == quad2) {
        dir = {1, 1};
    } else if(mn == quad3) {
        dir = {-1, 1};
    } else {
        dir = {-1, -1};
    }

    for(int i=1; i<=499; ++i) {
        king += dir;
        if(mat[king.first][king.second]) {
            king.first -= dir.first;
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            assert(id == -1 && x == -1 && y == -1);
            return 0;
        } else {
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            if(id == -1 && x == -1 && y == -1) {
                return 0;
            }
            --mat[rooks[id].first][rooks[id].second];
            rooks[id].first = x, rooks[id].second = y;
            ++mat[rooks[id].first][rooks[id].second];
        }
    }

}


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n'

const int MOD = 1e9+7; //998244353;
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;

void setIO(const string& s) {
//	ios_base::sync_with_stdio(false);
//	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

pair<int,int> operator+(const pair<int,int>& a, const pair<int,int>& b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

void operator+=(pair<int,int>& a, const pair<int,int>& b) {
    a.first += b.first, a.second += b.second;
}

int mat[1000][1000];
pair<int,int> rooks[667];

signed main() {
    setIO("input");

    pair<int,int> king;
    cin >> king.first >> king.second;
    for(int i=1; i<=666; ++i) {
        cin >> rooks[i].first >> rooks[i].second;
        ++mat[rooks[i].first][rooks[i].second];
    }

    for(int i=0; i<=1; ++i) {
        int& cur = (i==0?king.first:king.second);
        while(cur != 500) {
                if(cur > 500) --cur;
                else ++cur;
                cout << king.first << ' ' << king.second << endl;
                int id,x,y; cin >> id >> x >> y;
                if(id == -1 && x == -1 && y == -1) {
                    return 0;
                }
                --mat[rooks[id].first][rooks[id].second];
                rooks[id].first = x, rooks[id].second = y;
                ++mat[rooks[id].first][rooks[id].second];
        }
    }

    int quad1 = 0, quad2 = 0, quad3 = 0, quad4 = 0;
    for(int i=1; i<=499; ++i) for(int j=501; j<=999; ++j) quad1 += mat[i][j];
    for(int i=1; i<=499; ++i) for(int j=1; j<=499; ++j) quad2 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=1; j<=499; ++j) quad3 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=501; j<=999; ++j) quad4 += mat[i][j];

    pair<int,int> dir;
    int mn = min({quad1, quad2, quad3, quad4});
    if(mn == quad1) {
        dir = {1, -1};
    } else if(mn == quad2) {
        dir = {1, 1};
    } else if(mn == quad3) {
        dir = {-1, 1};
    } else {
        dir = {-1, -1};
    }

    for(int i=1; i<=499; ++i) {
        king += dir;
        if(mat[king.first][king.second]) {
            king.first -= dir.first;
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            assert(id == -1 && x == -1 && y == -1);
            return 0;
        } else {
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            if(id == -1 && x == -1 && y == -1) {
                return 0;
            }
            --mat[rooks[id].first][rooks[id].second];
            rooks[id].first = x, rooks[id].second = y;
            ++mat[rooks[id].first][rooks[id].second];
        }
    }

}


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n'

const int MOD = 1e9+7; //998244353;
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;

void setIO(const string& s) {
	ios_base::sync_with_stdio(false);
//	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

pair<int,int> operator+(const pair<int,int>& a, const pair<int,int>& b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

void operator+=(pair<int,int>& a, const pair<int,int>& b) {
    a.first += b.first, a.second += b.second;
}

int mat[1000][1000];
pair<int,int> rooks[667];

signed main() {
    setIO("input");

    pair<int,int> king;
    cin >> king.first >> king.second;
    for(int i=1; i<=666; ++i) {
        cin >> rooks[i].first >> rooks[i].second;
        ++mat[rooks[i].first][rooks[i].second];
    }

    for(int i=0; i<=1; ++i) {
        int& cur = (i==0?king.first:king.second);
        while(cur != 500) {
                if(cur > 500) --cur;
                else ++cur;
                cout << king.first << ' ' << king.second << endl;
                int id,x,y; cin >> id >> x >> y;
                if(id == -1 && x == -1 && y == -1) {
                    return 0;
                }
                --mat[rooks[id].first][rooks[id].second];
                rooks[id].first = x, rooks[id].second = y;
                ++mat[rooks[id].first][rooks[id].second];
        }
    }

    int quad1 = 0, quad2 = 0, quad3 = 0, quad4 = 0;
    for(int i=1; i<=499; ++i) for(int j=501; j<=999; ++j) quad1 += mat[i][j];
    for(int i=1; i<=499; ++i) for(int j=1; j<=499; ++j) quad2 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=1; j<=499; ++j) quad3 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=501; j<=999; ++j) quad4 += mat[i][j];

    pair<int,int> dir;
    int mn = min({quad1, quad2, quad3, quad4});
    if(mn == quad1) {
        dir = {1, -1};
    } else if(mn == quad2) {
        dir = {1, 1};
    } else if(mn == quad3) {
        dir = {-1, 1};
    } else {
        dir = {-1, -1};
    }

    for(int i=1; i<=499; ++i) {
        king += dir;
        if(mat[king.first][king.second]) {
            king.first -= dir.first;
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            assert(id == -1 && x == -1 && y == -1);
            return 0;
        } else {
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            if(id == -1 && x == -1 && y == -1) {
                return 0;
            }
            --mat[rooks[id].first][rooks[id].second];
            rooks[id].first = x, rooks[id].second = y;
            ++mat[rooks[id].first][rooks[id].second];
        }
    }

}


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n'

const int MOD = 1e9+7; //998244353;
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;

void setIO(const string& s) {
//	ios_base::sync_with_stdio(false);
//	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

pair<int,int> operator+(const pair<int,int>& a, const pair<int,int>& b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

void operator+=(pair<int,int>& a, const pair<int,int>& b) {
    a.first += b.first, a.second += b.second;
}

int mat[1000][1000];
pair<int,int> rooks[667];

signed main() {
    setIO("input");

    pair<int,int> king;
    cin >> king.first >> king.second;
    for(int i=1; i<=666; ++i) {
        cin >> rooks[i].first >> rooks[i].second;
        ++mat[rooks[i].first][rooks[i].second];
    }

    for(int i=0; i<=1; ++i) {
        int& cur = (i==0?king.first:king.second);
        while(cur != 500) {
                if(cur > 500) --cur;
                else ++cur;
                cout << king.first << ' ' << king.second << endl;
                int id,x,y; cin >> id >> x >> y;
                if(id == -1 && x == -1 && y == -1) {
                    return 0;
                }
                --mat[rooks[id].first][rooks[id].second];
                rooks[id].first = x, rooks[id].second = y;
                ++mat[rooks[id].first][rooks[id].second];
        }
    }

    int quad1 = 0, quad2 = 0, quad3 = 0, quad4 = 0;
    for(int i=1; i<=499; ++i) for(int j=501; j<=999; ++j) quad1 += mat[i][j];
    for(int i=1; i<=499; ++i) for(int j=1; j<=499; ++j) quad2 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=1; j<=499; ++j) quad3 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=501; j<=999; ++j) quad4 += mat[i][j];

    pair<int,int> dir;
    int mn = min({quad1, quad2, quad3, quad4});
    if(mn == quad1) {
        dir = {1, -1};
    } else if(mn == quad2) {
        dir = {1, 1};
    } else if(mn == quad3) {
        dir = {-1, 1};
    } else {
        dir = {-1, -1};
    }

    for(int i=1; i<=499; ++i) {
        king += dir;
        if(mat[king.first][king.second]) {
            king.first -= dir.first;
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            assert(id == -1 && x == -1 && y == -1);
            return 0;
        } else {
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            if(id == -1 && x == -1 && y == -1) {
                return 0;
            }
            --mat[rooks[id].first][rooks[id].second];
            rooks[id].first = x, rooks[id].second = y;
            ++mat[rooks[id].first][rooks[id].second];
        }
    }

    cout << "0 0 0" << endl;

}


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n'

const int MOD = 1e9+7; //998244353;
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;

void setIO(const string& s) {
//	ios_base::sync_with_stdio(false);
//	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

pair<int,int> operator+(const pair<int,int>& a, const pair<int,int>& b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

int mat[1000][1000];
pair<int,int> rooks[667];

signed main() {
    setIO("input");

    pair<int,int> king;
    cin >> king.first >> king.second;
    for(int i=1; i<=666; ++i) {
        cin >> rooks[i].first >> rooks[i].second;
        ++mat[rooks[i].first][rooks[i].second];
    }

    for(int i=0; i<=1; ++i) {
        int& cur = (i==0?king.first:king.second);
        while(cur != 500) {
                if(cur > 500) --cur;
                else ++cur;
                cout << king.first << ' ' << king.second << endl;
                int id,x,y; cin >> id >> x >> y;
                if(id == -1 && x == -1 && y == -1) {
                    return 0;
                }
                --mat[rooks[id].first][rooks[id].second];
                rooks[id].first = x, rooks[id].second = y;
                ++mat[rooks[id].first][rooks[id].second];
            }
    }

    int quad1 = 0, quad2 = 0, quad3 = 0, quad4 = 0;
    for(int i=1; i<=499; ++i) for(int j=501; j<=999; ++j) quad1 += mat[i][j];
    for(int i=1; i<=499; ++i) for(int j=1; j<=499; ++j) quad2 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=1; j<=499; ++j) quad3 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=501; j<=999; ++j) quad4 += mat[i][j];

    pair<int,int> dir;
    int mn = min({quad1, quad2, quad3, quad4});
    if(mn == quad1) {
        dir = {1, -1};
    } else if(mn == quad2) {
        dir = {1, 1};
    } else if(mn == quad3) {
        dir = {-1, 1};
    } else {
        dir = {-1, -1};
    }

    for(int i=1; i<=499; ++i) {
        pair<int,int> nxt = king + dir;
        if(mat[nxt.first][nxt.second]) {
            nxt.first -= dir.first;
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            assert(id == -1 && x == -1 && y == -1);
            return 0;
        } else {
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            if(id == -1 && x == -1 && y == -1) {
                return 0;
            }
            --mat[rooks[id].first][rooks[id].second];
            rooks[id].first = x, rooks[id].second = y;
            ++mat[rooks[id].first][rooks[id].second];
        }
    }

//    cout << "0 0 0" << endl;

}


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n'

const int MOD = 1e9+7; //998244353;
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;

void setIO(const string& s) {
//	ios_base::sync_with_stdio(false);
//	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

pair<int,int> operator+(const pair<int,int>& a, const pair<int,int>& b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

pair<int,int> operator+=(pair<int,int>& a, const pair<int,int>& b) {
    a.first += b.first, a.second += b.second;
    return a;
}

int mat[1000][1000];
pair<int,int> rooks[667];

signed main() {
    setIO("input");

    pair<int,int> king;
    cin >> king.first >> king.second;
    for(int i=1; i<=666; ++i) {
        cin >> rooks[i].first >> rooks[i].second;
        ++mat[rooks[i].first][rooks[i].second];
    }

    for(int i=0; i<=1; ++i) {
        int& cur = (i==0?king.first:king.second);
        while(cur != 500) {
                if(cur > 500) --cur;
                else ++cur;
                cout << king.first << ' ' << king.second << endl;
                int id,x,y; cin >> id >> x >> y;
                if(id == -1 && x == -1 && y == -1) {
                    return 0;
                }
                --mat[rooks[id].first][rooks[id].second];
                rooks[id].first = x, rooks[id].second = y;
                ++mat[rooks[id].first][rooks[id].second];
        }
    }

    int quad1 = 0, quad2 = 0, quad3 = 0, quad4 = 0;
    for(int i=1; i<=499; ++i) for(int j=501; j<=999; ++j) quad1 += mat[i][j];
    for(int i=1; i<=499; ++i) for(int j=1; j<=499; ++j) quad2 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=1; j<=499; ++j) quad3 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=501; j<=999; ++j) quad4 += mat[i][j];

    pair<int,int> dir;
    int mn = min({quad1, quad2, quad3, quad4});
    if(mn == quad1) {
        dir = {1, -1};
    } else if(mn == quad2) {
        dir = {1, 1};
    } else if(mn == quad3) {
        dir = {-1, 1};
    } else {
        dir = {-1, -1};
    }

    for(int i=1; i<=499; ++i) {
        king += dir;
        if(mat[king.first][king.second]) {
            king.first -= dir.first;
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            assert(id == -1 && x == -1 && y == -1);
            return 0;
        } else {
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            if(id == -1 && x == -1 && y == -1) {
                return 0;
            }
            --mat[rooks[id].first][rooks[id].second];
            rooks[id].first = x, rooks[id].second = y;
            ++mat[rooks[id].first][rooks[id].second];
        }
    }

}


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n'

const int MOD = 1e9+7; //998244353;
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;

void setIO(const string& s) {
//	ios_base::sync_with_stdio(false);
//	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

pair<int,int> operator+(const pair<int,int>& a, const pair<int,int>& b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

void operator+=(pair<int,int> a, const pair<int,int>& b) {
    a.first += b.first, a.second += b.second;
}

int mat[1000][1000];
pair<int,int> rooks[667];

signed main() {
    setIO("input");

    pair<int,int> king;
    cin >> king.first >> king.second;
    for(int i=1; i<=666; ++i) {
        cin >> rooks[i].first >> rooks[i].second;
        ++mat[rooks[i].first][rooks[i].second];
    }

    for(int i=0; i<=1; ++i) {
        int& cur = (i==0?king.first:king.second);
        while(cur != 500) {
                if(cur > 500) --cur;
                else ++cur;
                cout << king.first << ' ' << king.second << endl;
                int id,x,y; cin >> id >> x >> y;
                if(id == -1 && x == -1 && y == -1) {
                    return 0;
                }
                --mat[rooks[id].first][rooks[id].second];
                rooks[id].first = x, rooks[id].second = y;
                ++mat[rooks[id].first][rooks[id].second];
        }
    }

    int quad1 = 0, quad2 = 0, quad3 = 0, quad4 = 0;
    for(int i=1; i<=499; ++i) for(int j=501; j<=999; ++j) quad1 += mat[i][j];
    for(int i=1; i<=499; ++i) for(int j=1; j<=499; ++j) quad2 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=1; j<=499; ++j) quad3 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=501; j<=999; ++j) quad4 += mat[i][j];

    pair<int,int> dir;
    int mn = min({quad1, quad2, quad3, quad4});
    if(mn == quad1) {
        dir = {1, -1};
    } else if(mn == quad2) {
        dir = {1, 1};
    } else if(mn == quad3) {
        dir = {-1, 1};
    } else {
        dir = {-1, -1};
    }

    for(int i=1; i<=499; ++i) {
        king += dir;
        if(mat[king.first][king.second]) {
            king.first -= dir.first;
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            assert(id == -1 && x == -1 && y == -1);
            return 0;
        } else {
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            if(id == -1 && x == -1 && y == -1) {
                return 0;
            }
            --mat[rooks[id].first][rooks[id].second];
            rooks[id].first = x, rooks[id].second = y;
            ++mat[rooks[id].first][rooks[id].second];
        }
    }

}


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n'

const int MOD = 1e9+7; //998244353;
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;

void setIO(const string& s) {
//	ios_base::sync_with_stdio(false);
//	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

pair<int,int> operator+(const pair<int,int>& a, const pair<int,int>& b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

pair<int,int>& operator+=(pair<int,int>& a, const pair<int,int>& b) {
    a.first += b.first, a.second += b.second;
    return a;
}

int mat[1000][1000];
pair<int,int> rooks[667];

signed main() {
    setIO("input");

    pair<int,int> king;
    cin >> king.first >> king.second;
    for(int i=1; i<=666; ++i) {
        cin >> rooks[i].first >> rooks[i].second;
        ++mat[rooks[i].first][rooks[i].second];
    }

    for(int i=0; i<=1; ++i) {
        int& cur = (i==0?king.first:king.second);
        while(cur != 500) {
                if(cur > 500) --cur;
                else ++cur;
                cout << king.first << ' ' << king.second << endl;
                int id,x,y; cin >> id >> x >> y;
                if(id == -1 && x == -1 && y == -1) {
                    return 0;
                }
                --mat[rooks[id].first][rooks[id].second];
                rooks[id].first = x, rooks[id].second = y;
                ++mat[rooks[id].first][rooks[id].second];
        }
    }

    int quad1 = 0, quad2 = 0, quad3 = 0, quad4 = 0;
    for(int i=1; i<=499; ++i) for(int j=501; j<=999; ++j) quad1 += mat[i][j];
    for(int i=1; i<=499; ++i) for(int j=1; j<=499; ++j) quad2 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=1; j<=499; ++j) quad3 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=501; j<=999; ++j) quad4 += mat[i][j];

    pair<int,int> dir;
    int mn = min({quad1, quad2, quad3, quad4});
    if(mn == quad1) {
        dir = {1, -1};
    } else if(mn == quad2) {
        dir = {1, 1};
    } else if(mn == quad3) {
        dir = {-1, 1};
    } else {
        dir = {-1, -1};
    }

    for(int i=1; i<=499; ++i) {
        king += dir;
        if(mat[king.first][king.second]) {
            king.first -= dir.first;
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            assert(id == -1 && x == -1 && y == -1);
            return 0;
        } else {
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            if(id == -1 && x == -1 && y == -1) {
                return 0;
            }
            --mat[rooks[id].first][rooks[id].second];
            rooks[id].first = x, rooks[id].second = y;
            ++mat[rooks[id].first][rooks[id].second];
        }
    }

}


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n'

const int MOD = 1e9+7; //998244353;
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;

void setIO(const string& s) {
//	ios_base::sync_with_stdio(false); cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

pair<int,int> operator+(const pair<int,int>& a, const pair<int,int>& b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

void operator+=(pair<int,int>& a, const pair<int,int>& b) {
    a.first += b.first, a.second += b.second;
}

int mat[1000][1000];
pair<int,int> rooks[667];

signed main() {
    setIO("input");

    pair<int,int> king;
    cin >> king.first >> king.second;
    for(int i=1; i<=666; ++i) {
        cin >> rooks[i].first >> rooks[i].second;
        ++mat[rooks[i].first][rooks[i].second];
    }

    for(int i=0; i<=1; ++i) {
        int& cur = (i==0?king.first:king.second);
        while(cur != 500) {
                if(cur > 500) --cur;
                else ++cur;
                cout << king.first << ' ' << king.second << endl;
                int id,x,y; cin >> id >> x >> y;
                if(id == -1 && x == -1 && y == -1) {
                    return 0;
                }
                --mat[rooks[id].first][rooks[id].second];
                rooks[id].first = x, rooks[id].second = y;
                ++mat[rooks[id].first][rooks[id].second];
        }
    }

    int quad1 = 0, quad2 = 0, quad3 = 0, quad4 = 0;
    for(int i=1; i<=499; ++i) for(int j=501; j<=999; ++j) quad1 += mat[i][j];
    for(int i=1; i<=499; ++i) for(int j=1; j<=499; ++j) quad2 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=1; j<=499; ++j) quad3 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=501; j<=999; ++j) quad4 += mat[i][j];

    pair<int,int> dir;
    int mn = min({quad1, quad2, quad3, quad4});
    if(mn == quad1) {
        dir = {1, -1};
    } else if(mn == quad2) {
        dir = {1, 1};
    } else if(mn == quad3) {
        dir = {-1, 1};
    } else {
        dir = {-1, -1};
    }

    for(int i=1; i<=499; ++i) {
        king += dir;
        if(mat[king.first][king.second]) {
            king.first -= dir.first;
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            assert(id == -1 && x == -1 && y == -1);
            return 0;
        } else {
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            if(id == -1 && x == -1 && y == -1) {
                return 0;
            }
            --mat[rooks[id].first][rooks[id].second];
            rooks[id].first = x, rooks[id].second = y;
            ++mat[rooks[id].first][rooks[id].second];
        }
    }

}


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n'

const int MOD = 1e9+7; //998244353;
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;

void setIO(const string& s) {
//	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

pair<int,int> operator+(const pair<int,int>& a, const pair<int,int>& b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

void operator+=(pair<int,int>& a, const pair<int,int>& b) {
    a.first += b.first, a.second += b.second;
}

int mat[1000][1000];
pair<int,int> rooks[667];

signed main() {
    setIO("input");

    pair<int,int> king;
    cin >> king.first >> king.second;
    for(int i=1; i<=666; ++i) {
        cin >> rooks[i].first >> rooks[i].second;
        ++mat[rooks[i].first][rooks[i].second];
    }

    for(int i=0; i<=1; ++i) {
        int& cur = (i==0?king.first:king.second);
        while(cur != 500) {
                if(cur > 500) --cur;
                else ++cur;
                cout << king.first << ' ' << king.second << endl;
                int id,x,y; cin >> id >> x >> y;
                if(id == -1 && x == -1 && y == -1) {
                    return 0;
                }
                --mat[rooks[id].first][rooks[id].second];
                rooks[id].first = x, rooks[id].second = y;
                ++mat[rooks[id].first][rooks[id].second];
        }
    }

    int quad1 = 0, quad2 = 0, quad3 = 0, quad4 = 0;
    for(int i=1; i<=499; ++i) for(int j=501; j<=999; ++j) quad1 += mat[i][j];
    for(int i=1; i<=499; ++i) for(int j=1; j<=499; ++j) quad2 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=1; j<=499; ++j) quad3 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=501; j<=999; ++j) quad4 += mat[i][j];

    pair<int,int> dir;
    int mn = min({quad1, quad2, quad3, quad4});
    if(mn == quad1) {
        dir = {1, -1};
    } else if(mn == quad2) {
        dir = {1, 1};
    } else if(mn == quad3) {
        dir = {-1, 1};
    } else {
        dir = {-1, -1};
    }

    for(int i=1; i<=499; ++i) {
        king += dir;
        if(mat[king.first][king.second]) {
            king.first -= dir.first;
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            assert(id == -1 && x == -1 && y == -1);
            return 0;
        } else {
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            if(id == -1 && x == -1 && y == -1) {
                return 0;
            }
            --mat[rooks[id].first][rooks[id].second];
            rooks[id].first = x, rooks[id].second = y;
            ++mat[rooks[id].first][rooks[id].second];
        }
    }

}


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n'

const int MOD = 1e9+7; //998244353;
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;

void setIO(const string& s) {
//	ios_base::sync_with_stdio(false);
//	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

pair<int,int> operator+(const pair<int,int>& a, const pair<int,int>& b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

void operator+=(pair<int,int>& a, const pair<int,int>& b) {
    a.first += b.first, a.second += b.second;
}

int mat[1000][1000];
pair<int,int> rooks[667];

signed main() {
    setIO("input");

    pair<int,int> king;
    cin >> king.first >> king.second;
    for(int i=1; i<=666; ++i) {
        cin >> rooks[i].first >> rooks[i].second;
        ++mat[rooks[i].first][rooks[i].second];
    }

    for(int i=0; i<=1; ++i) {
        int& cur = (i==0?king.first:king.second);
        while(cur != 500) {
                if(cur > 500) --cur;
                else ++cur;
                cout << king.first << ' ' << king.second << endl;
                int id,x,y; cin >> id >> x >> y;
                if(id == -1 && x == -1 && y == -1) {
                    return 0;
                }
                --mat[rooks[id].first][rooks[id].second];
                rooks[id].first = x, rooks[id].second = y;
                ++mat[rooks[id].first][rooks[id].second];
        }
    }

    int quad1 = 0, quad2 = 0, quad3 = 0, quad4 = 0;
    for(int i=1; i<=499; ++i) for(int j=501; j<=999; ++j) quad1 += mat[i][j];
    for(int i=1; i<=499; ++i) for(int j=1; j<=499; ++j) quad2 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=1; j<=499; ++j) quad3 += mat[i][j];
    for(int i=501; i<=999; ++i) for(int j=501; j<=999; ++j) quad4 += mat[i][j];

    pair<int,int> dir;
    int mn = min({quad1, quad2, quad3, quad4});
    if(mn == quad1) {
        dir = {1, -1};
    } else if(mn == quad2) {
        dir = {1, 1};
    } else if(mn == quad3) {
        dir = {-1, 1};
    } else {
        dir = {-1, -1};
    }

    for(int i=1; i<=499; ++i) {
        king += dir;
        if(mat[king.first][king.second]) {
            king.first -= dir.first;
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            assert(id == -1 && x == -1 && y == -1);
            return 0;
        } else {
            cout << king.first << ' ' << king.second << endl;
            int id,x,y; cin >> id >> x >> y;
            if(id == -1 && x == -1 && y == -1) {
                return 0;
            }
            --mat[rooks[id].first][rooks[id].second];
            rooks[id].first = x, rooks[id].second = y;
            ++mat[rooks[id].first][rooks[id].second];
        }
    }

//    cout << "0 0 0" << endl;

}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
void solve()
{
    bool flag=0;
    int k,nx,ny;
    while(cin>>k>>nx>>ny&&k+nx+ny)
    {
        if(k==-1&&nx==-1&&ny==-1) return;
        Point &cur=p[k];
        maze[cur.x][cur.y]=0;
        maze[nx][ny]=1;
        cntx[cur.x]--,cnty[cur.y]--;
        cur.x=nx,cur.y=ny;
        cntx[cur.x]++,cnty[cur.y]++;
        if(!flag)
        {
            if(curx==1&&cury==1) flag=1;
            else{
                if(curx==1||maze[curx-1][cury-1])
                    nx=curx,ny=cury-1;
                else if(cury==1) ny=cury,nx=curx-1;
                else{
                    nx=curx-1,ny=cury-1;
                }
            }
        }
        if(flag)
        {
            nx=curx+1,ny=cury+1;
            if(maze[nx][ny]) nx--;
        }
        cout<<nx<<" "<<ny<<endl;
        cout.flush();
        curx=nx,cury=ny;
    }
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();
}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
bool move(int dx,int dy)
{
    curx+=dx,cury+=dy;
    if(maze[curx][cury])
    {
        if(dx>0) curx--;
        else cury--;
    }
    cout<<curx<<" "<<cury<<endl;
    int k,nx,ny;
    cin>>k>>nx>>ny;
    if(k+nx+ny==-3||k+nx+ny==0) return 0;
    maze[p[k].x][p[k].y]=0;
    cntx[p[k].x]--;cnty[p[k].y]--;
    cntx[nx]++,cnty[ny]++;
    maze[nx][ny]=1;
    p[k].x=nx;p[k].y=ny;
    return 1;
}
int calc()
{
    int d[5]={0};
    for(int i=1;i<=999;i++)
    {
        if(cntx[i]>500) d[1]++,d[4]++;
        else d[2]++,d[3]++;
        if(cnty[i]>500) d[1]++,d[2]++;
        else d[3]++,d[4]++;
    }
    for(int i=1;i<=4;i++)
        if(d[i]>=500) return i;
}
void solve()
{
    while(curx<500) if(!move(1,0)) return;
    while(curx>500) if(!move(-1,0)) return;
    while(cury<500) if(!move(0,1)) return;
    while(cury>500) if(!move(-1,0)) return;
    int direct=calc();
    if(direct==1) while(move(-1,1));
    else if(direct==2) while(move(-1,-1));
    else if(direct==3) while(move(1,-1));
    else while(move(1,1));
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();

}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
bool move(int dx,int dy)
{
    curx+=dx,cury+=dy;
    if(maze[curx][cury])
    {
        if(dx) curx-=dx;
        else cury-=dy;
    }
    cout<<curx<<" "<<cury<<endl;
    int k,nx,ny;
    cin>>k>>nx>>ny;
    if(k+nx+ny==-3||k+nx+ny==0) return 0;
    maze[p[k].x][p[k].y]=0;
    cntx[p[k].x]--;cnty[p[k].y]--;
    cntx[nx]++,cnty[ny]++;
    maze[nx][ny]=1;
    p[k].x=nx;p[k].y=ny;
    return 1;
}
int calc()
{
    int d[5]={0};
    for(int i=1;i<=999;i++)
    {
        if(cntx[i]>500) d[1]++,d[4]++;
        else d[2]++,d[3]++;
        if(cnty[i]>500) d[1]++,d[2]++;
        else d[3]++,d[4]++;
    }
    for(int i=1;i<=4;i++)
        if(d[i]>=500) return i;
}
void solve()
{
    while(curx<500) if(!move(1,0)) return;
    while(curx>500) if(!move(-1,0)) return;
    while(cury<500) if(!move(0,1)) return;
    while(cury>500) if(!move(0,-1)) return;
    int direct=calc();
    if(direct==1) while(move(-1,1));
    else if(direct==2) while(move(-1,-1));
    else if(direct==3) while(move(1,-1));
    else while(move(1,1));
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();

}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
bool move(int dx,int dy)
{
    curx+=dx,cury+=dy;
    if(maze[curx][cury])
    {
        if(dx) curx-=dx;
        else cury-=dy;
    }
    cout<<curx<<" "<<cury<<endl;
    int k,nx,ny;
    cin>>k>>nx>>ny;
    if(k+nx+ny==-3||k+nx+ny==0) return 0;
    maze[p[k].x][p[k].y]=0;
    cntx[p[k].x]--;cnty[p[k].y]--;
    cntx[nx]++,cnty[ny]++;
    maze[nx][ny]=1;
    p[k].x=nx;p[k].y=ny;
    return 1;
}
int calc()
{
    int d[5]={0};
    for(int i=1;i<=999;i++)
    {
        if(cntx[i]>500) d[1]++,d[4]++;
        else d[2]++,d[3]++;
        if(cnty[i]>500) d[1]++,d[2]++;
        else d[3]++,d[4]++;
    }
    int tar=0;
    for(int i=1;i<=4;i++)
        tar=max(tar,d[i]);
    for(int i=1;i<=4;i++)
        if(tar==d[i]) return i;
}
void solve()
{
    while(curx<500) if(!move(1,0)) return;
    while(curx>500) if(!move(-1,0)) return;
    while(cury<500) if(!move(0,1)) return;
    while(cury>500) if(!move(0,-1)) return;
    int direct=calc();
    if(direct==1) while(move(-1,1));
    else if(direct==2) while(move(-1,-1));
    else if(direct==3) while(move(1,-1));
    else while(move(1,1));
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();

}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
bool move(int dx,int dy)
{
    curx+=dx,cury+=dy;
    if(maze[curx][cury])
    {
        if(dx>0) curx--;
        else cury--;
    }
    cout<<curx<<" "<<cury<<endl;
    int k,nx,ny;
    cin>>k>>nx>>ny;
    maze[p[k].x][p[k].y]=0;
    cntx[p[k].x]--;cnty[p[k].y]--;
    cntx[nx]++,cnty[ny]++;
    maze[nx][ny]=1;
    p[k].x=nx;p[k].y=ny;
    return k+nx+ny==-3;
}
int calc()
{
    int d[5]={0};
    for(int i=1;i<=999;i++)
    {
        if(cntx[i]>500) d[1]++,d[4]++;
        else d[2]++,d[3]++;
        if(cnty[i]>500) d[1]++,d[2]++;
        else d[3]++,d[4]++;
    }
    for(int i=1;i<=4;i++)
        if(d[i]>=500) return i;
}
void solve()
{
    while(curx<500) if(!move(1,0)) return;
    while(curx>500) if(!move(-1,0)) return;
    while(cury<500) if(!move(0,1)) return;
    while(cury>500) if(!move(-1,0)) return;
    int direct=calc();
    if(direct==1) while(!move(-1,1));
    else if(direct==2) while(!move(-1,-1));
    else if(direct==3) while(!move(1,-1));
    else while(!move(1,1));
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();

}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
bool move(int dx,int dy)
{
    curx+=dx,cury+=dy;
    if(maze[curx][cury])
    {
        if(dx) curx-=dx;
        else cury-=dy;
    }
    cout<<curx<<" "<<cury<<endl;
    int k=0,nx=0,ny=0;
    cin>>k>>nx>>ny;
    if(k+nx+ny==-3||k+nx+ny==0) return 0;
    maze[p[k].x][p[k].y]=0;
    cntx[p[k].x]--;cnty[p[k].y]--;
    cntx[nx]++,cnty[ny]++;
    maze[nx][ny]=1;
    p[k].x=nx;p[k].y=ny;
    return 1;
}
int calc()
{
    int d[5]={0};
    for(int i=1;i<=999;i++)
    {
        if(i<500)
        {
            d[1]+=cntx[i];
            d[2]+=cntx[i];
            d[2]+=cnty[i];
            d[3]+=cnty[i];
        }
        else{
            d[3]+=cntx[i];
            d[4]+=cntx[i];
            d[1]+=cnty[i];
            d[4]+=cnty[i];
        }
    }
    int tar=0;
    for(int i=1;i<=4;i++)
        tar=max(tar,d[i]);
    for(int i=1;i<=4;i++)
        if(tar==d[i]) return i;
}
void solve()
{
    while(curx<500) move(1,0);
    while(curx>500) move(-1,0);
    while(cury<500) move(0,1);
    while(cury>500) move(0,-1);
    int direct=calc();
    if(direct==1) while(move(-1,1));
    else if(direct==2) while(move(-1,-1));
    else if(direct==3) while(move(1,-1));
    else while(move(1,1));
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();

}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
void solve()
{
    bool flag=0;
    int k=0,nx=0,ny=0;
    do
    {
        if(k==-1&&nx==-1&&ny==-1) return;
        Point &cur=p[k];
        maze[cur.x][cur.y]=0;
        maze[nx][ny]=1;
        cntx[cur.x]--,cnty[cur.y]--;
        cur.x=nx,cur.y=ny;
        cntx[cur.x]++,cnty[cur.y]++;
        if(!flag)
        {
            if(curx==1&&cury==1) flag=1;
            else{
                if(curx==1||maze[curx-1][cury-1])
                    nx=curx,ny=cury-1;
                else if(cury==1) ny=cury,nx=curx-1;
                else{
                    nx=curx-1,ny=cury-1;
                }
            }
        }
        if(flag)
        {
            nx=curx+1,ny=cury+1;
            if(maze[nx][ny]) nx--;
        }
        cout<<nx<<" "<<ny<<endl;
        cout.flush();
        curx=nx,cury=ny;
    }while(cin>>k>>nx>>ny&&k+nx+ny);
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();
}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
bool move(int dx,int dy)
{
    curx+=dx,cury+=dy;
    if(maze[curx][cury])
    {
        if(dx>0) curx--;
        else cury--;
    }
    cout<<curx<<" "<<cury<<endl;
    cout.flush();
    int k,nx,ny;
    cin>>k>>nx>>ny;
    maze[p[k].x][p[k].y]=0;
    cntx[p[k].x]--;cnty[p[k].y]--;
    cntx[nx]++,cnty[ny]++;
    maze[nx][ny]=1;
    p[k].x=nx;p[k].y=ny;
    return k+nx+ny==-3;
}
int calc()
{
    int d[5]={0};
    for(int i=1;i<=999;i++)
    {
        if(cntx[i]>500) d[1]++,d[4]++;
        else d[2]++,d[3]++;
        if(cnty[i]>500) d[1]++,d[2]++;
        else d[3]++,d[4]++;
    }
    for(int i=1;i<=4;i++)
        if(d[i]>=500) return i;
}
void solve()
{
    while(curx<500) if(!move(1,0)) return;
    while(curx>500) if(!move(-1,0)) return;
    while(cury<500) if(!move(0,1)) return;
    while(cury>500) if(!move(-1,0)) return;
    int direct=calc();
    if(direct==1) while(!move(-1,1));
    else if(direct==2) while(!move(-1,-1));
    else if(direct==3) while(!move(1,-1));
    else while(!move(1,1));
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();

}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
bool move(int dx,int dy)
{
    curx+=dx,cury+=dy;
    if(maze[curx][cury])
    {
        if(dx) curx-=dx;
        else cury-=dy;
    }
    cout<<curx<<" "<<cury<<endl;
    int k,nx,ny;
    cin>>k>>nx>>ny;
    if(k+nx+ny==-3||k+nx+ny==0) return 0;
    maze[p[k].x][p[k].y]=0;
    cntx[p[k].x]--;cnty[p[k].y]--;
    cntx[nx]++,cnty[ny]++;
    maze[nx][ny]=1;
    p[k].x=nx;p[k].y=ny;
    return 1;
}
int calc()
{
    int d[5]={0};
    for(int i=1;i<=999;i++)
    {
        if(i<500)
        {
            d[1]+=cntx[i];
            d[2]+=cntx[i];
            d[2]+=cnty[i];
            d[3]+=cnty[i];
        }
        else{
            d[3]+=cntx[i];
            d[4]+=cntx[i];
            d[1]+=cnty[i];
            d[2]+=cnty[i];
        }
    }
    int tar=0;
    for(int i=1;i<=4;i++)
        tar=max(tar,d[i]);
    for(int i=1;i<=4;i++)
        if(tar==d[i]) return i;
}
void solve()
{
    while(curx<500) if(!move(1,0)) return;
    while(curx>500) if(!move(-1,0)) return;
    while(cury<500) if(!move(0,1)) return;
    while(cury>500) if(!move(0,-1)) return;
    int direct=calc();
    if(direct==1) while(move(-1,1));
    else if(direct==2) while(move(-1,-1));
    else if(direct==3) while(move(1,-1));
    else while(move(1,1));
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();

}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
bool move(int dx,int dy)
{
    curx+=dx,cury+=dy;
    if(maze[curx][cury])
    {
        if(dx>0) curx--;
        else cury--;
    }
    cout<<curx<<" "<<cury<<endl;
    cout.flush();
    int k,nx,ny;
    cin>>k>>nx>>ny;
    if(k+nx+ny==-3||k+nx+ny==0) return 0;
    maze[p[k].x][p[k].y]=0;
    cntx[p[k].x]--;cnty[p[k].y]--;
    cntx[nx]++,cnty[ny]++;
    maze[nx][ny]=1;
    p[k].x=nx;p[k].y=ny;
    return 1;
}
int calc()
{
    int d[5]={0};
    for(int i=1;i<=999;i++)
    {
        if(cntx[i]>500) d[1]++,d[4]++;
        else d[2]++,d[3]++;
        if(cnty[i]>500) d[1]++,d[2]++;
        else d[3]++,d[4]++;
    }
    for(int i=1;i<=4;i++)
        if(d[i]>=500) return i;
}
void solve()
{
    while(curx<500) if(!move(1,0)) return;
    while(curx>500) if(!move(-1,0)) return;
    while(cury<500) if(!move(0,1)) return;
    while(cury>500) if(!move(-1,0)) return;
    int direct=calc();
    if(direct==1) while(!move(-1,1));
    else if(direct==2) while(!move(-1,-1));
    else if(direct==3) while(!move(1,-1));
    else while(!move(1,1));
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();

}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
void solve()
{
    bool flag=0;
    int k,nx,ny;
    while(cin>>k>>nx>>ny&&k+nx+ny)
    {
        if(k==-1&&nx==-1&&ny==-1) return;
        Point &cur=p[k];
        maze[cur.x][cur.y]=0;
        maze[nx][ny]=1;
        cntx[cur.x]--,cnty[cur.y]--;
        cur.x=nx,cur.y=ny;
        cntx[cur.x]++,cnty[cur.y]++;
        if(!flag)
        {
            if(curx==1&&cury==1) flag=1;
            else{
                if(curx==1||maze[curx-1][cury-1])
                    nx=curx,ny=cury-1;
                else if(cury==1) ny=cury,nx=curx-1;
                else{
                    nx=curx-1,ny=cury-1;
                }
            }
        }
        if(flag)
        {
            nx=curx+1,ny=cury+1;
            if(maze[nx][ny]) nx--;
        }
        cout<<nx<<" "<<ny<<endl;
        curx=nx,cury=ny;
    }
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();
}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
bool move(int dx,int dy)
{
    curx+=dx,cury+=dy;
    if(maze[curx][cury])
    {
        if(dx>0) curx--;
        else cury--;
    }
    cout<<curx<<" "<<cury<<endl;
    int k,nx,ny;
    cin>>k>>nx>>ny;
    if(k+nx+ny==-3||k+nx+ny==0) return 0;
    maze[p[k].x][p[k].y]=0;
    cntx[p[k].x]--;cnty[p[k].y]--;
    cntx[nx]++,cnty[ny]++;
    maze[nx][ny]=1;
    p[k].x=nx;p[k].y=ny;
    return 1;
}
int calc()
{
    int d[5]={0};
    for(int i=1;i<=999;i++)
    {
        if(cntx[i]>500) d[1]++,d[4]++;
        else d[2]++,d[3]++;
        if(cnty[i]>500) d[1]++,d[2]++;
        else d[3]++,d[4]++;
    }
    for(int i=1;i<=4;i++)
        if(d[i]>=500) return i;
}
void solve()
{
    while(curx<500) if(!move(1,0)) return;
    while(curx>500) if(!move(-1,0)) return;
    while(cury<500) if(!move(0,1)) return;
    while(cury>500) if(!move(0,-1)) return;
    int direct=calc();
    if(direct==1) while(move(-1,1));
    else if(direct==2) while(move(-1,-1));
    else if(direct==3) while(move(1,-1));
    else while(move(1,1));
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();

}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
bool move(int dx,int dy)
{
    curx+=dx,cury+=dy;
    if(maze[curx][cury])
    {
        if(dx) curx-=dx;
        else cury-=dy;
    }
    cout<<curx<<" "<<cury<<endl;
    int k=0,nx=0,ny=0;
    cin>>k>>nx>>ny;
    if(k+nx+ny==-3||k+nx+ny==0) return 0;
    maze[p[k].x][p[k].y]=0;
    cntx[p[k].x]--;cnty[p[k].y]--;
    cntx[nx]++,cnty[ny]++;
    maze[nx][ny]=1;
    p[k].x=nx;p[k].y=ny;
    return 1;
}
int calc()
{
    int d[5]={0};
    for(int i=1;i<=666;i++)
    {
        if(p[i].x<500&&p[i].y<500) d[1]++,d[2]++,d[3]++;
        else if(p[i].y<500) d[2]++,d[3]++,d[4]++;
        else if(p[i].y>500&&p[i].x>500) d[1]++,d[4]++,d[3]++;
        else d[1]++,d[2]++,d[4]++;
    }
    int tar=0;
    for(int i=1;i<=4;i++)
        tar=max(tar,d[i]);
    for(int i=1;i<=4;i++)
        if(tar==d[i]) return i;
}
void solve()
{
    while(curx<500) move(1,0);
    while(curx>500) move(-1,0);
    while(cury<500) move(0,1);
    while(cury>500) move(0,-1);
    int direct=calc();
    if(direct==1) while(move(-1,1));
    else if(direct==2) while(move(-1,-1));
    else if(direct==3) while(move(1,-1));
    else while(move(1,1));
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();

}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
bool move(int dx,int dy)
{
    curx+=dx,cury+=dy;
    if(maze[curx][cury])
    {
        if(dx>0) curx--;
        else cury--;
    }
    cout<<curx<<" "<<cury<<endl;
    int k,nx,ny;
    cin>>k>>nx>>ny;
    maze[p[k].x][p[k].y]=0;
    cntx[p[k].x]--;cnty[p[k].y]--;
    cntx[nx]++,cnty[ny]++;
    maze[nx][ny]=1;
    p[k].x=nx;p[k].y=ny;
    return k+nx+ny==-3;
}
int calc()
{
    int d[5]={0};
    for(int i=1;i<=999;i++)
    {
        if(cntx[i]>500) d[1]++,d[4]++;
        else d[2]++,d[3]++;
        if(cnty[i]>500) d[1]++,d[2]++;
        else d[3]++,d[4]++;
    }
    for(int i=1;i<=4;i++)
        if(d[i]>=500) return i;
}
void solve()
{
    while(curx<500) if(!move(1,0)) return;
    while(curx>500) if(!move(-1,0)) return;
    while(cury<500) if(!move(0,1)) return;
    while(cury>500) if(!move(-1,0)) return;
    int direct=calc();
    if(direct==1) while(!move(-1,1));
    else if(direct==2) while(!move(-1,-1));
    else if(direct==3) while(!move(1,-1));
    else while(!move(1,1));
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }

}


#include<bits/stdc++.h>
using namespace std;
struct Point{
    int x,y;
}p[1000];
int maze[1000][1000];
int curx,cury;
int cntx[1000],cnty[1000];
bool move(int dx,int dy)
{
    curx+=dx,cury+=dy;
    if(maze[curx][cury])
    {
        if(dx) curx-=dx;
        else cury-=dy;
    }
    cout<<curx<<" "<<cury<<endl;
    int k=0,nx=0,ny=0;
    cin>>k>>nx>>ny;
    if(k+nx+ny==-3||k+nx+ny==0) return 0;
    maze[p[k].x][p[k].y]=0;
    cntx[p[k].x]--;cnty[p[k].y]--;
    cntx[nx]++,cnty[ny]++;
    maze[nx][ny]=1;
    p[k].x=nx;p[k].y=ny;
    return 1;
}
int calc()
{
    int d[5]={0};
    for(int i=1;i<=999;i++)
    {
        if(i<500)
        {
            d[1]+=cntx[i];
            d[2]+=cntx[i];
            d[2]+=cnty[i];
            d[3]+=cnty[i];
        }
        else{
            d[3]+=cntx[i];
            d[4]+=cntx[i];
            d[1]+=cnty[i];
            d[4]+=cnty[i];
        }
    }
    int tar=0;
    for(int i=1;i<=4;i++)
        tar=max(tar,d[i]);
    for(int i=1;i<=4;i++)
        if(tar==d[i]) return i;
}
void solve()
{
    while(curx<500) if(!move(1,0)) return;
    while(curx>500) if(!move(-1,0)) return;
    while(cury<500) if(!move(0,1)) return;
    while(cury>500) if(!move(0,-1)) return;
    int direct=calc();
    if(direct==1) while(move(-1,1));
    else if(direct==2) while(move(-1,-1));
    else if(direct==3) while(move(1,-1));
    else while(move(1,1));
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(cntx,0,sizeof(cntx));
    memset(cnty,0,sizeof(cnty));
    cin>>curx>>cury;
    for(int i=1;i<=666;i++)
    {
        cin>>p[i].x>>p[i].y;
        maze[p[i].x][p[i].y]=1;
        cntx[p[i].x]++;
        cnty[p[i].y]++;
    }
    solve();

}


#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());

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<1000; i++) {
				for (int j=1; j<1000; j++) {
					NW++; NE++; SW++; SE++;
					if (i < 500 && j < 500) SE--;
					if (i < 500 && j > 500) SW--;
					if (i > 500 && j < 500) NE--;
					if (i > 500 && j > 500) NW--;
				}
			}

			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());

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 == -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 == 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());

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 << "-4 -4\n"; 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<1000; i++) {
				for (int j=1; j<1000; j++) {
					if (!occ[i][j]) continue;
					NW++; NE++; SW++; SE++;
					if (i < 500 && j < 500) SE--;
					if (i < 500 && j > 500) SW--;
					if (i > 500 && j < 500) NE--;
					if (i > 500 && j > 500) NW--;
				}
			}

			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  *
\**********************************************/