This page is still under construction.

Parts of this page are still being built. What you see may change.

Cow Checkers

Time limit1sMemory limit128 MB

Summary
For each starting square on a large board, decide the winner of a two-player game with three kinds of leftward or downward moves.
Level

Medium7 of 10

Topics
Game theory, Math
Solved
No attempts yet

Problem

One day Bessie decides to challenge Farmer John to a game of "Cow Checkers". The game is played on an M×NM \times N checkerboard (1≤M≤1,000,0001 \le M \le 1{,}000{,}000, 1≤N≤1,000,0001 \le N \le 1{,}000{,}000) that initially contains a single checker piece at coordinates (X,Y)(X, Y) (0≤X<M0 \le X < M, 0≤Y<N0 \le Y < N). The bottom-left square of the board has coordinates (0,0)(0, 0), and the top-right square has coordinates (M−1,N−1)(M-1, N-1). Bessie always moves first, and then the two players alternate turns.

On each turn a player makes one of the following three moves:

  1. Move the piece to any square in the same row that lies to the left of its current position.
  2. Move the piece to any square in the same column that lies below its current position.
  3. Move the piece to the square that is kk squares down and kk squares to the left of its current square, where kk is any positive integer for which the destination square is still on the board.

The first player who is unable to move (i.e., because the piece is at (0,0)(0, 0)) loses. Given that Bessie always goes first and both players play optimally, determine who wins.

For TT games (1≤T≤1,0001 \le T \le 1{,}000), read a new starting position X,YX, Y for each game and decide the winner.

Input

  • Line 1: Two space-separated integers MM and NN
  • Line 2: A single integer TT
  • Lines 3 through T+2T+2: Two space-separated integers XX and YY on each line

Output

For each game print one line containing either Farmer John or Bessie, depending on who wins that game. Print TT lines in total.

Hint

Consider one game on a 3×33 \times 3 checkerboard with the piece initially at (1,1)(1, 1) (the center of the board).

Bessie can initially move the piece only to (1,0)(1, 0), (0,1)(0, 1), or (0,0)(0, 0). Bessie can win immediately by moving the piece to (0,0)(0, 0).

Examples3

  1. Example 1

    Input
    3 3
    1
    1 1
    
    Expected output
    Bessie
    
  2. Example 2

    Input
    10 10
    1
    1 2
    
    Expected output
    Farmer John
    
  3. Example 3

    Input
    1 1
    1
    0 0
    
    Expected output
    Farmer John