#include <cstdio>
#include <cstdlib>
#include <cassert>

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

int w, h, x, y;

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

int main() {
  scanf("%*d"); // i don't use type of horse

  assert(scanf("%d%d", &w, &h) == 2);
  assert(scanf("%d%d", &x, &y) == 2);

  srand(239);
  while (1) {
    int move;
    while (1) {
      move = rand() % 8;
      if (correct(x + dx[move], y + dy[move])) {
        break;
      }
    }

    printf("%d\n", move);
    fflush(stdout);

    int horseMove; // not used
    assert(scanf("%d", &horseMove) == 1);
  }
  return 0;
}
