Make a Sequence

Time limit1sMemory limit128 MB

Problem

Two players play a three-dimensional variant of Tic-Tac-Toe. They drop balls into a cubic board and try to form a straight run of balls of a fixed length. Your task is to simulate such games and report the winner of each one.

A game is controlled by two parameters: the board size $n$ and the target sequence length $m$.

The exact rules are as follows.

  1. Two players, Black and White, move alternately, and Black moves first.
  2. There are $n \times n$ vertical pegs, and each peg can hold up to $n$ balls. A peg is identified by its $x$- and $y$-coordinates ($1 \le x, y \le n$), and a ball on a peg by its $z$-coordinate ($1 \le z \le n$). At the start of a game every peg is empty.
  3. On a turn, a player chooses one of the $n \times n$ pegs and drops a ball of their own color onto it. The ball obeys gravity: it comes to rest directly on top of the highest ball already on that peg, or on the floor if the peg is empty. In other words, a player chooses the $x$- and $y$-coordinates of the ball but not its $z$-coordinate.
  4. The goal is to form an $m$-sequence: $m$ consecutive balls of the same color along a straight line. A player who forms a run of length $m$ or more wins immediately. For example, black balls at $(5, 1, 2)$, $(5, 2, 2)$, and $(5, 3, 2)$ form a 3-sequence.

A sequence may run along an axis or along a diagonal. There are exactly 13 distinct directions; opposite directions are treated as the same one.

  • Axis-aligned directions (3). For example $(3, 1, 2)$, $(4, 1, 2)$, $(5, 1, 2)$.
  • Two-dimensional diagonals (6). For example $(2, 3, 1)$, $(3, 3, 2)$, $(4, 3, 3)$.
  • Three-dimensional diagonals (4). For example $(5, 1, 3)$, $(4, 2, 4)$, $(3, 3, 5)$.

You are given the record of each game and must decide who wins.

Because three-dimensional runs are hard for people to notice, players sometimes keep going after the game is already decided. Every move made after the winner is determined must be ignored: only the first $m$-sequence counts, and any later sequences do not change the winner.

A game need not end in a victory. If no peg can accept another ball, the game is a draw. A game may also be abandoned before any $m$-sequence is formed, which is also a draw.

Input

The input consists of several datasets, each recording one game.

A dataset begins with a line containing three positive integers $n$, $m$, and $p$ separated by single spaces, where $3 \le m \le n \le 7$ and $1 \le p \le n^3$. Here $n$ and $m$ are the board size and the sequence length, and $p$ is the number of moves played.

Each of the next $p$ lines contains two positive integers $x$ and $y$ ($1 \le x, y \le n$): the player to move drops a ball on peg $(x, y)$. No peg ever receives more than $n$ balls during a game.

The end of the input is a line containing three zeros: 0 0 0. It is not part of any dataset.

Output

For each dataset, print exactly one line.

If a player wins, print the winner (Black or White), then a single space, then the number of the move on which the game was decided. If the game ends in a draw, print Draw. Do not print any other characters.