#include <iostream>
#include <fstream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <list>
#include <cstring>

#define all(x) (x).begin(),(x).end()

using namespace std;

const int nmax = 1e3;

int dxhorse[] = { 0, 0, 0, -1, 1 };
int dyhorse[] = { 0, -1, 1, 0, 0 };

int dx[] = { 0, 0, 0, 1, 1, 1, -1, -1, -1 };
int dy[] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };

int n,m;

int hedgehogX, hedgehogY;

int possibleHorseMinX;
int possibleHorseMaxX;
int possibleHorseMinY;
int possibleHorseMaxY;

int totalHorseDX;
int totalHorseDY;

int norm(int dcoord) 
{
	if (dcoord > 0) return 1;
	if (dcoord < 0) return -1;
	return 0;
}

void updateX(int& x) {
	x = min(x, m);
	x = max(1, x);
}

void updateY(int& y) {
	y = min(y, n);
	y = max(1, y);
}

void makeHorseMove(int& x, int& y)
{
	int answer, movedx, movedy;
	scanf("%d%d%d", &answer, &movedx, &movedy);
	if (answer == 1) exit(0);
	x += movedx;
	y += movedy;
	possibleHorseMinX += movedx; updateX(possibleHorseMinX); 
	possibleHorseMaxX += movedx; updateX(possibleHorseMaxX); 
	possibleHorseMinY += movedy; updateY(possibleHorseMinY); 
	possibleHorseMaxY += movedy; updateY(possibleHorseMaxY); 
	totalHorseDX += movedx;
	totalHorseDY += movedy;
}

bool correct(int x, int y)
{
	return 1 <= x && x <= m && 1 <= y && y <= n;
}

bool correctHorse(int x, int y)
{
	return correct(x, y) && (possibleHorseMinX <= x && x <= possibleHorseMaxX && possibleHorseMinY <= y && y <= possibleHorseMaxY);
}

void catchHorse(int horseX, int horseY)
{
	horseX += totalHorseDX;
	horseY += totalHorseDY;
	bool found = 0;
	while (!found)
	{
		if (!correctHorse(horseX, horseY)) return;
		int dx = norm(horseX - hedgehogX);
		int dy = norm(horseY - hedgehogY);
		hedgehogX += dx;
		hedgehogY += dy;
		printf("%d %d %d\n", dx, dy, found = (hedgehogX == horseX && hedgehogY == horseY));
		fflush(stdout);
		makeHorseMove(horseX, horseY);
	}
}

int main()
{
	scanf("%d %d", &n, &m);
	scanf("%d %d", &hedgehogX, &hedgehogY);
	possibleHorseMinX = 1;
	possibleHorseMinY = 1;
	possibleHorseMaxX = m;
	possibleHorseMaxY = n;

	for (int i = 1; i <= m; i ++)
	{
		for (int j = 1; j <= n; j ++)
			catchHorse(i, j);
	}
	assert(false);
	return 0;
};
