Problem:
Problem B:
Make a Sequence
Your company’s next product will be a new game, which is a three-dimensional variant of the
classic game “Tic-Tac-Toe”. Two players place balls in a three-dimensional space (board), and
try to make a sequence of a certain length.
People believe that it is fun to play the game, but they still cannot fix the values of some
parameters of the game. For example, what size of the board makes the game most exciting?
Parameters currently under discussion are the board size (we call it
n
in the following) and the
length of the sequence (
m
). In order to determine these parameter values, you are requested to
write a computer simulator of the game.
You can see several snapshots of the game in Figures 1-3. These figures correspond to the three
datasets given in the Sample Input.
Figure 1: A game with
n
=
m
= 3
Here are the precise rules of the game.
Two players, Black and White, play alternately. Black plays first.
There are
n
×
n
vertical pegs. Each peg can accommodate up to
n
balls. A peg can be
     specified by its
x
- and
y
-coordinates (1 ≤
x
,
y
≤
n
). A ball on a peg can be specified by
     its
z
-coordinate (1 ≤
z
≤
n
). At the beginning of a game, there are no balls on any of the
     pegs.
Figure 2: A game with
n
=
m
= 3 (White made a 3-sequence before Black)
On his turn, a player chooses one of
n
×
n
pegs, and puts a ball of his color onto the peg.
   The ball follows the law of gravity. That is, the ball stays just above the top-most ball
   on the same peg or on the floor (if there are no balls on the peg). Speaking differently, a
   player can choose
x
- and
y
-coordinates of the ball, but he cannot choose its
z
-coordinate.
The objective of the game is to make an
m
-sequence. If a player makes an
m
-sequence or
   longer of his color, he wins. An
m
-sequence is a row of
m
consecutive balls of the same
   color. For example, black balls in positions (5, 1, 2), (5, 2, 2) and (5, 3, 2) form a 3-sequence.
   A sequence can be horizontal, vertical, or diagonal. Precisely speaking, there are 13
   possible directions to make a sequence, categorized as follows.
Figure 3: A game with
n
= 4,
m
= 3 (Black made two 4-sequences)
(a) One-dimensional axes. For example, (3, 1, 2), (4, 1, 2) and (5, 1, 2) is a 3-sequence.
  There are three directions in this category.
(b) Two-dimensional diagonals. For example, (2, 3, 1), (3, 3, 2) and (4, 3, 3) is a 3-sequence.
    There are six directions in this category.
(c) Three-dimensional diagonals. For example, (5, 1, 3), (4, 2, 4) and (3, 3, 5) is a 3-
    sequence. There are four directions in this category.
Note that we do not distinguish between opposite directions.
As the evaluation process of the game, people have been playing the game several times changing
the parameter values. You are given the records of these games. It is your job to write a computer
program which determines the winner of each recorded game.
Since it is difficult for a human to find three-dimensional sequences
...(truncated)

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}

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

int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  while(1){
    int n,m,p;cin >> n >> m >> p;
    if(!n)break;
    vvvi mem(n,vvi(n,vi(n,-1)));
    auto ch = [&](int cl){
      rep(i,0,n)rep(j,0,n)rep(k,0,n)rep(dir,0,13){
        bool is = true;
        rep(l,0,m){
          int ni = i + dx[dir]*l;
          int nj = j + dy[dir]*l;
          int nk = k + dz[dir]*l;
          if(ni < 0 || ni >= n || nj < 0 || nj >= n || nk < 0 || nk >= n){is = false;break;}
          if(mem[ni][nj][nk] != cl){is = false;break;}
        }
        if(is)return true;
      }
      return false;
    };
    vvi cl(n,vi(n));
    int win = -1,moves = -1;
    rep(_,0,p){
      int x,y;cin >> x >> y;
      x--;y--;
      mem[x][y][cl[x][y]++] = _ & 1;
      if(win == -1 && ch(_ & 1))win = _ & 1,moves = _+1;
    }
    if(win == -1)cout << "Draw\n";
    else if(win == 0)cout << "Black " << moves << "\n";
    else cout << "White " << moves << "\n";
  }
  

  return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 3364
final_rank: 7

code_snippet: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	while (true) {
		int N, M, P;
		cin >> N >> M >> P;
		if (N == 0 && M == 0 && P == 0) {
			break;
		}
		vector<vector<vector<int> > > A(N, vector<vector<int> >(N, vector<int>(N, -1)));
		vector<vector<vector<int> > > C(N, vector<vector<int> >(N, vector<int>(N, -1)));
		vector<vector<int> > H(N, vector<int>(N, 0));
		for (int i = 0; i < P; i++) {
			int x, y;
			cin >> x >> y;
			x--; y--;
			A[H[x][y]][x][y] = i;
			C[H[x][y]][x][y] = i % 2;
			H[x][y]++;
		}
		auto inside = [&](int x, int y, int z) -> bool {
			return 0 <= x && x < N && 0 <= y && y < N && 0 <= z && z < N;
		};
		int ans = P;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				for (int k = 0; k < N; k++) {
					for (int dx = -1; dx <= +1; dx++) {
						for (int dy = -1; dy <= +1; dy++) {
							for (int dz = -1; dz <= +1; dz++) {
								if (dx | dy | dz) {
									bool f = true;
									vector<int> sa(M), sc(M);
									for (int l = 0; l < M; l++) {
										int x = i + dx * l;
										int y = j + dy * l;
										int z = k + dz * l;
										if (!inside(x, y, z)) {
											f = false;
											break;
										}
										sa[l] = A[x][y][z];
										sc[l] = C[x][y][z];
									}
									if (sc[0] == -1) {
										f = false;
									}
									if (f) {
										for (int l = 0; l < M; l++) {
											if (sc[l] != sc[0]) {
												f = false;
											}
										}
									}
									if (f) {
										int t = *max_element(sa.begin(), sa.end());
										ans = min(ans, t);
									}
								}
							}
						}
					}
				}
			}
		}
		if (ans == P) {
			cout << "Draw" << endl;
		} else {
			cout << (ans % 2 == 0 ? "Black" : "White") << ' ' << ans + 1 << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3464
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

void Solve(int N, int M, int P, vector<pair<int,int>>& A) {
    vector X(N, vector(N, vector<int>(N,-1)));
    vector H(N, vector<int>(N,0));
    rep(_,0,P) {
        int B = _ % 2;
        X[A[_].first][A[_].second][H[A[_].first][A[_].second]] = B;
        H[A[_].first][A[_].second]++;
    rep(i,0,N) {
        rep(j,0,N) {
            rep(k,0,N) {
                rep(di,-1,2) {
                    rep(dj,-1,2) {
                        rep(dk,-1,2) {
                            if (di == 0 && dj == 0 && dk == 0) break;
                            bool check = true;
                            rep(l,0,M) {
                                int ni = i + di * l;
                                int nj = j + dj * l;
                                int nk = k + dk * l;
                                if (ni < 0 || nj < 0 || nk < 0 || ni >= N || nj >= N || nk >= N) {
                                    check = false;
                                    break;
                                }
                                if (X[ni][nj][nk] != B) {
                                    check = false;
                                    break;
                                }
                            }
                            if (check) {
                                cout << (B == 0 ? "Black" : "White") << ' ' << _ + 1 << endl;
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    }
    cout << "Draw" << endl;
    return;
}

int main() {
while(1) {
    int N, M, P;
    cin >> N >> M >> P;
    if (N == 0) return 0;
    vector<pair<int,int>> A(P);
    rep(i,0,P) cin >> A[i].first >> A[i].second, A[i].first--, A[i].second--;
    Solve(N,M,P,A);
}
}
accuracy: 1
time_ms: 240
memory_kb: 3516
final_rank: 16

code_snippet: #include <iostream>
#include <vector>
using namespace std;
#define ALL(v) begin(v),end(v)

int N,M,P;

bool check(const vector<vector<vector<int>>>& board, int side) {
  for (int sx = 0; sx < N; ++sx) {
    for (int sy = 0; sy < N; ++sy) {
      for (int sz = 0; sz < N; ++sz) {
        for (int dx = -1; dx < 2; ++dx) {
          for (int dy = -1; dy < 2; ++dy) {
            for (int dz = -1; dz < 2; ++dz) {
              if (dx==0 and dy==0 and dz==0) continue;
              bool ok = true;
              for (int i = 0; i < M; ++i) {
                int x = sx + dx * i;
                int y = sy + dy * i;
                int z = sz + dz * i;
                if (0 <= x && x < N &&
                0 <= y && y < N &&
                0 <= z && z < N &&
                board[z][y][x] == side) {
                  //
                } else {
                  ok = false;
                  break;
                }
              }
              if (ok) return true;
            }
          }
        }
      }
    }
  }
  return false;
}

int main(void) {
  while (true) {
    cin >> N >> M >> P;
    if (N == 0 and M == 0 and P == 0) break;
    
    vector<pair<int, int>> hand;
    for (int i = 0; i < P; ++i) {
      int x, y;
      cin >> x >> y;
      --x; --y;
      hand.emplace_back(x, y);
    }
    
    vector<vector<vector<int>>> board(N, vector<vector<int>>(N, vector<int>(N, -1)));
    vector<vector<int>> next(N, vector<int>(N, 0));
    int side = 0;
    bool decided = false;
    for (int i = 0; i < P; ++i) {
      auto [x, y] = hand[i];
      int z = next[y][x];
      board[z][y][x] = side;
      next[y][x]++;
      
      if (check(board, side)) {
        cout << (side ? "White" : "Black") << ' ' << i + 1 << endl;
        decided = true;
        break;
      }
      side = 1 - side;
    }
    if (!decided) cout << "Draw" << endl;
  }
  
}
accuracy: 1
time_ms: 290
memory_kb: 3140
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define LL_INF 9223372036854775807
#define INT_INF 2147483647
using namespace std;
using ll = long long;

int main()
{
  while (true)
  {
    int n, m, p;
    cin >> n >> m >> p;
    if (n == 0 and m == 0 and p == 0)
    {
      return 0;
    }
    vector<pair<int, int>> v(p);
    for (pair<int, int> &i : v)
    {
      cin >> i.first >> i.second;
      i.first--;
      i.second--;
    }
    vector<vector<vector<int>>> board(n, vector<vector<int>>(n, vector<int>(n, 2)));
    vector<vector<int>> dir = {{1, 1, -1}, {0, 1, -1}, {-1, 1, -1}, {1, 0, -1}, {0, 0, -1}, {-1, 0, -1}, {-1, -1, -1}, {0, -1, -1}, {1, -1, -1}, {1, 1, 0}, {0, 1, 0}, {-1, 1, 0}, {1, 0, 0}, {-1, 0, 0}, {-1, -1, 0}, {0, -1, 0}, {1, -1, 0}, {1, 1, 1}, {0, 1, 1}, {-1, 1, 1}, {1, 0, 1}, {0, 0, 1}, {-1, 0, 1}, {-1, -1, 1}, {0, -1, 1}, {1, -1, 1}};
    int x, y, z;
    bool ok;
    for (int i = 0; i < p; i++)
    {
      x = v[i].first;
      y = v[i].second;
      ok = false;
      for (int j = 0; j < p; j++)
      {
        if (board[x][y][j] == 2)
        {
          board[x][y][j] = i % 2;
          z = j;
          break;
        }
      }

      for (vector<int> j : dir)
      {
        int cnt = 1, n_x = x, n_y = y, n_z = z;
        while (0 <= (n_x + j[0]) and (n_x + j[0]) < n and 0 <= (n_y + j[1]) and (n_y + j[1]) < n and 0 <= (n_z + j[2]) and (n_z + j[2]) < n)
        {
          n_x += j[0];
          n_y += j[1];
          n_z += j[2];
          if (board[x][y][z] != board[n_x][n_y][n_z])
          {
            n_x -= j[0];
            n_y -= j[1];
            n_z -= j[2];
            break;
          }
        }
        while (0 <= (n_x - j[0]) and (n_x - j[0]) < n and 0 <= (n_y - j[1]) and (n_y - j[1]) < n and 0 <= (n_z - j[2]) and (n_z - j[2]) < n)
        {
          n_x -= j[0];
          n_y -= j[1];
          n_z -= j[2];
          if (board[x][y][z] == board[n_x][n_y][n_z])
          {
            cnt++;
          }
          else
          {
            break;
          }
        }
        if (m <= cnt)
        {
          if (board[x][y][z] == 0)
          {
            cout << "Black ";
          }
          else
          {
            cout << "White ";
          }
          cout << i + 1 << endl;
          ok = true;
          break;
        }
        if (ok)
        {
          break;
        }
      }
      if (ok)
      {
        break;
      }
    }
    if (!ok)
    {
      cout << "Draw" << endl;
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3204
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

vector<pair<int, int>> rle(const vector<int>& A) {
    vector<pair<int, int>> res{};
    for (int i = 0 ; i < (int)A.size() ; i++) {
        if (res.empty() or res.back().first != A[i]) {
            res.push_back({ A[i], 1 });
        }
        else {
            res.back().second++;
        }
    }
    return res;
}


bool solve() {
    int N, M, P; cin >> N >> M >> P;
    if (N == 0) return false;
    vector<vector<vector<int>>> table(N, vector(N, vector(N, 0)));
    using pos = tuple<int, int, int>;
    vector<int> d = { -1, 0, 1 };
    string ans{};

    for (int i = 0 ; i < P ; i++) {
        int nowcol = (i % 2 == 0 ? 1 : 2);
        int x, y; cin >> x >> y;
        x--; y--;
        pos put{ -1, -1, -1 };
        for (int j = 0 ; j < N ; j++) {
            if (table[x][y][j] == 0) {
                table[x][y][j] = nowcol;
                put = pos{ x, y, j };
                break;
            }
        }
        assert(get<0>(put) != -1);
        auto [sx, sy, sz] = put;
        bool win = false;

        auto in = [&](int x, int y, int z) -> bool {
            return 0 <= x and x < N and 0 <= y and y < N and 0 <= z and z < N;
        };

        for (auto dx : d) for (auto dy : d) for (auto dz : d) {
            if (dx == 0 and dy == 0 and dz == 0) continue;
            vector<int> arr{};
            for (int j = -10 ; j < 10 ; j++) {
                int x = sx + j * dx, y = sy + j * dy, z = sz + j * dz;
                if (!in(x, y, z)) continue;
                arr.push_back(table[x][y][z]);
                for (auto [col, cnt] : rle(arr)) {
                    if (col == nowcol and cnt >= M) win = true;
                }
            }
        }

        
        if (win and ans.empty()) {
            ans = string((nowcol == 1 ? "Black" : "White")) + string(" ") + to_string(i + 1);
        }
    }
    if (ans.empty()) ans = "Draw";
    cout << ans << endl;
    return true;
}

int main() {
    while (solve()) ;
}
accuracy: 1
time_ms: 220
memory_kb: 3216
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

void fall(vector<vector<vector<int>>> &pegs, int color, pair<int, int> p) {
  auto [x, y] = p;
  int z = pegs[y][x].size() - 1;
  pegs[y][x][z] = color;
  z--;
  while (z >= 0 && pegs[y][x][z] == 0) {
    swap(pegs[y][x][z], pegs[y][x][z + 1]);
    z--;
  }
}

bool win(vector<vector<vector<int>>> &pegs, int color, int m) {
  int n = pegs.size();
  const int dy[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, /*9*/  0,  0,  0,  0,  0,  0,  0,  0,  0, /*18*/  1,  1,  1,  1,  1,  1,  1,  1,  1};
  const int dx[] = {-1, -1, -1,  0,  0,  0,  1,  1,  1, /*9*/ -1, -1, -1,  0,  0,  0,  1,  1,  1, /*18*/  0,  0,  0,  0,  0,  0,  0,  0,  0};
  const int dz[] = {-1,  0,  1, -1,  0,  1, -1,  0,  1, /*9*/ -1,  0,  1, -1,  0,  1, -1,  0,  1, /*18*/ -1,  0,  1,  0, -1,  1,  -1, 0,  1};
  auto in_ranges = [&](int a) {
    return 0 <= a && a < n;
  };

  for (int k = 0; k < 27; k++) {
    if (dy[k] == 0 && dx[k] == 0 && dz[k] == 0) continue;
    vector len(n, vector(n, vector(n, 0)));
    for (int y = 0; y < n; y++) {
      for (int x = 0; x < n; x++) {
        for (int z = 0; z < n; z++) {
          auto f = [&](auto &&f, int y, int x, int z, int k) {
            // cout << x << ' ' << y << ' ' << z << endl;
            if (!in_ranges(y) || !in_ranges(x) || !in_ranges(z) || pegs[y][x][z] != color) return 0;
            else if (len[y][x][z] > 0) return len[y][x][z];

            int ny = y + dy[k];
            int nx = x + dx[k];
            int nz = z + dz[k];

            return len[y][x][z] = f(f, ny, nx, nz, k) + 1;
          };

          if (f(f, y, x, z, k) >= m)
            return true;
        }
      }
    }
  }

  return false;
}

int main() {
  int n, m, p;

  while (cin >> n >> m >> p, n > 0) {
    vector pegs(n, vector(n, vector(n, 0))); // 0: empty, 1: black, 2: white
    vector balls(p, make_pair(0, 0));
    for (auto &a: balls) {
      cin >> a.first >> a.second;
      a.first--, a.second--;
    }

    int winner = 0;
    int moves = 0;
    for (int i = 0; i < p; i++) {
      if (i & 1) { 
        fall(pegs, 2, balls[i]);
        if (win(pegs, 2, m)) {
          winner = 2;
          moves = i;
          break;
        }
      }
      else  {
        fall(pegs, 1, balls[i]);
        if (win(pegs, 1, m)) {
          winner = 1;
          moves = i;
          break;
        }
      }
    }

    if (winner == 0) {
      cout << "Draw" << endl;
    }
    else if (winner == 1) {
      cout << "Black" << ' ' << moves + 1 << endl;
    }
    else {
      cout << "White" << ' ' << moves + 1 << endl;
    }
  }
}
accuracy: 1
time_ms: 560
memory_kb: 3472
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define foa(s, v) for(auto &s : v)
#define all(v) v.begin(), v.end()
#define REPname(a,b,c,d,...) d
#define rep(...) REPname(__VA_ARGS__, REP2, REP1, REP0)(__VA_ARGS__)
#define REP2(i,l,r) for(int i = l; i < r; i++)
#define REP1(i, x) REP2(i,0,x)
#define REP0(x) REP1(SPJ, x)
#define sz(x) int(x.size())

template <class T>
using V=vector<T>;

template <class T>
using VV=vector<V<T>>;

template<class T>
using pqmin = priority_queue<T, V<T>, greater<T>>;
using ll = long long ;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = V<vll>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
template<class T>
inline bool chmax(T &a, T b){
	return a < b ? a=b, 1 : 0;
}
template <class T>
inline bool chmin(T &a, T b) {
	return a > b ? a = b, 1 : 0;
}

template <class T>
void view(T x) {
	cerr << x;
}

template <class T>
void view(V<T> v) {
	cerr << "{ ";
	foa(t, v) {view(t) ; cerr << ", ";}
	cerr << "}";
	cerr << endl;
}


template <class T>
void view(VV<T> v) {
	cerr << "{ ";
	foa(t, v) {view(t) ; cerr << ",\n";}
	cerr << "}";
	cerr << endl;
}


// template <c0lass T>
void view(int x) {
	cerr << x;
}

#ifdef LOCAL
void debug_out() {}
template <class T>
void debug_out(T x) {
	view(x);
}
template <class H, class... T>
void debug_out(H h, T... t) {
	view(h);
	cerr << ", ";
	debug_out(t...);
}
#define debug(...)                                           \
	do {                                                     \
		cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                              \
		cerr << "]\n";                                       \
	} while(0)
#else
#define debug(...) (void(0))
#endif
using vvi = V<vi>;

struct uf{
	vector<int> dat;
	uf(int n) : dat(n, -1) {}
	int root(int x) 
	{
		int& p = dat[x];
		if(p < 0) return x;
		return p = root(p);
	}
	bool merge(int x, int y) {
		x = root(x);
		y = root(y);
		if(x == y) return false;
		if(-dat[x] < -dat[y]) swap(x, y);
		dat[x] += dat[y];
		dat[y]  = x;
		return true;
	}
};

ll modpow(ll x, ll n, ll md){
	ll ret = 1 % md;
	while(n > 0){
		if(n & 1) {ret *= x; ret %= md;}
		n >>= 1;
		x *= x;
		x %= md;
	}
	if(ret < 0) ret += abs(md);
	return ret;
}

using S = ll;
using F = ll; // +
constexpr ll e = INF;
constexpr ll id = 0LL;
constexpr ll replace_e = e;
ll op(ll a, ll b) {return min(a,b);}
ll mapping(F f, S s) {return S(f+s);}
ll composition(F f, F g) {return f+g;}
struct node {
	node *l = nullptr;
	node *r = nullptr;
	int lo, hi;
	ll mset = e;
	ll madd = id;
	ll val = e;
	node(int lo, int hi) : lo(lo), hi(hi) {}
	node (vll& v, int lo, int hi) : lo(lo), hi(hi) {
		if(lo + 1 < hi) {
			int mid  = lo + (hi - lo) / 2;
			l  = new node (v, lo, mid);
			r = new node(v, mid, hi);
			val = op(l->val, r->val);
		}
		else {
			val  = v[lo];
		}
	}

	S query(int L, int R) {
		if(R <= lo || hi <= L) return e;
		if(L <=lo && hi  <= R) return val;
		push();
		return op(l->query(L, R), r->query(L,R));
	}

	void set(int L, int R, ll x) {
		if(R <= lo || hi <= L) return;
		if(L <= lo && hi <= R) mset = val = x, madd = id;
		else {
			push(), l->set (L, R, x) , r->set(L,R,x);
			val = op(l->val, r->val);
		}
	}

	void add(int L, int R, ll x) {
		if(R <= lo || hi <= L) return;
		if(L <= lo && hi <= R) {
			if(mset != replace_e) mset = mapping(x, mset);
			else madd = composition(x, madd);
			val = mapping(x, val);
		} else {
			push(), l->add(L, R, x), r->add(L, R, x);
			val = op(l->val, r->val);
		}
	}

	void push() {
		if(!l) {
			int mid = lo + (hi - lo) / 2;
			l = new node(lo, mid);
			r = new node(mid, hi);
		}
		if(mset != replace_e)
			l->set(lo, hi, mset), r->set(lo, hi, mset), mset = replace_e;
		else if(madd)
			l->add(lo, hi, madd), r->add(lo, hi, madd), madd = id;
	}
};

int solve(int n){ // first : 1, second : -1, draw : 0
	int win; cin >> win;
	int p; cin >> p;
	vector<vi> nxt(n, vi(n));
	vector brd(n, vector(n, vector<int>(n, 0)));
	const int fst = 1;
	const int snd = -1;
	V<pair<int, int>> hands;
	rep(p) {
		int x, y; cin >>x >> y;
		x--;
		y--;
		hands.emplace_back(x, y);
	}

	auto in = [&n](int x) { return 0 <= x && x < n ;};

	auto beam = [&](int sx, int sy, int sz, int mx, int my, int mz) {
		int plr = brd[sx].at(sy).at(sz);
		if(plr == 0) return 0;
		rep(win-1) {
			sx += mx;
			sy += my;
			sz += mz;
			if(!in(sx)) return 0;
			if(!in(sy)) return 0;
			if(!in(sz)) return 0;
			if(plr != brd.at(sx).at(sy).at(sz)) return 0;
		}

		return plr;
	};

	auto judge = [&]() -> int {
		rep(i, n) rep(j, n) rep(k, n) {
			rep(dx, -1, 2) rep(dy, -1, 2) rep(dz, -1, 2) {
				if(dx == 0 && dy == 0 && dz == 0) continue;
				int res = beam(i,j,k,dx, dy, dz);
				if(res) return res;
			}
		}

		return 0;
	};

	int now = fst;
	rep(i, int(hands.size())){
		int x, y;
		tie(x, y) = hands.at(i);
		int& pos = nxt[x][y];
		brd[x][y][pos] = now;
		pos++;
		int res = judge();
		if(res) {
			return i + 1;
		}
		now = -now;
	}

	return 0;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	srand((unsigned)time(NULL));
	int n;
	while(cin >> n && n) {
		int res  = solve(n);
		if(res == 0) cout << "Draw\n";
		else {
			if(res & 1) {
				cout << "Black ";
			}else {
				cout << "White ";
			}
			cout << res << '\n';
		}
	}
}
accuracy: 1
time_ms: 250
memory_kb: 3412
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rrep(i,l,r) for(int i=l;i<=r;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define unq(x) sort(all(x));x.erase(unique(all(x)),x.end())
//#define mod 1000000007
#define mod 998244353
//ll mod;
#define ad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
void readv(vector<ll> &a,ll n){
	rep(i,n){
		ll x;
		cin>>x;
		a.push_back(x);
	}
}
void outv(vector<ll> &a,ll n){
	rep(i,n){
		if(i>0)cout<<" ";
		cout<<a[i];
	}
	cout<<"\n";
}
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll gcd(ll a,ll b){
	return (b?gcd(b,a%b):a);
}
#define FACMAX 200010
ll fac[FACMAX],inv[FACMAX],ivf[FACMAX];
void initfac(){
	fac[0]=ivf[0]=inv[1]=1;
	for(ll i=1;i<FACMAX;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=1;i<FACMAX;i++){
		if(i>1)inv[i]=(mod-mod/i*inv[mod%i]%mod)%mod;
		ivf[i]=po(fac[i],mod-2);
	}
}
ll P(ll n,ll k){
	if(n<0||n<k)return 0;
	return fac[n]*ivf[n-k]%mod;
}
ll C(ll n,ll k){
	if(k<0||n<k)return 0;
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
ll H(ll n,ll k){
	return C(n+k-1,k);
}

ll n,m,p;
ll x[400],y[400];
ll dx[]={1,0,0,1,1,1,1,0,0,1,1,1,1};
ll dy[]={0,1,0,1,-1,0,0,1,1,1,1,-1,-1};
ll dz[]={0,0,1,0,0,1,-1,1,-1,1,-1,1,-1};

void solve(){
	vector<bool> v[7][7];
	rep(u,p){
		v[x[u]][y[u]].pb(u%2);
		rep(X,n)rep(Y,n)rep(Z,n){
			rep(s,13){
				ll cnt[2]={0,0};
				rep(i,m){
					ll Xi=X+dx[s]*i;
					ll Yi=Y+dy[s]*i;
					ll Zi=Z+dz[s]*i;
					if(!(0<=Xi&&Xi<n))break;
					if(!(0<=Yi&&Yi<n))break;
					if(!(0<=Zi&&Zi<v[Xi][Yi].size()))break;
					cnt[v[Xi][Yi][Zi]]++;
				}
				if(cnt[0]==m){
					cout<<"Black "<<u+1<<endl;
					return;
				}
				if(cnt[1]==m){
					cout<<"White "<<u+1<<endl;
					return;
				}
			}
		}
	}
	cout<<"Draw"<<endl;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	while(1){
		cin>>n>>m>>p;
		if(n==0&&m==0&&p==0)break;
		rep(i,p){
			cin>>x[i]>>y[i];
			x[i]--,y[i]--;
		}
		solve();
	}
}
accuracy: 1
time_ms: 170
memory_kb: 3452
final_rank: 12

code_snippet: #line 2 "library/KowerKoint/base.hpp"

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define END(...) { print(__VA_ARGS__); return; }

using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using ll = long long;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VS = vector<string>;
using VVS = vector<VS>;
using VVVS = vector<VVS>;
using VC = vector<char>;
using VVC = vector<VC>;
using VVVC = vector<VVC>;
using P = pair<int, int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VVVP = vector<VVP>;
using LP = pair<ll, ll>;
using VLP = vector<LP>;
using VVLP = vector<VLP>;
using VVVLP = vector<VVLP>;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr int DX[] = {1, 0, -1, 0};
constexpr int DY[] = {0, 1, 0, -1};

void print() { cout << '\n'; }
template<typename T>
void print(const T &t) { cout << t << '\n'; }
template<typename Head, typename... Tail>
void print(const Head &head, const Tail &... tail) {
    cout << head << ' ';
    print(tail...);
}

#ifdef ONLINE_JUDGE
template<typename... Args>
void dbg(const Args &... args) {}
#else
void dbg() { cerr << '\n'; }
template<typename T>
void dbg(const T &t) { cerr << t << '\n'; }
template<typename Head, typename... Tail>
void dbg(const Head &head, const Tail &... tail) {
    cerr << head << ' ';
    dbg(tail...);
}
#endif

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
    os << p.first << " " << p.second;
    return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
    is >> p.first >> p.second;
    return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
    for(int i = 0; i < (int) v.size(); i++) {
        os << v[i] << (i + 1 != (int) v.size() ? " " : "");
    }
    return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
    for(T &in : v) is >> in;
    return is;
}

template<typename T>
vector<vector<T>> split(typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, T val) {
    vector<vector<T>> res;
    vector<T> cur;
    for(auto it = begin; it != end; it++) {
        if(*it == val) {
            res.push_back(cur);
            cur.clear();
        } else cur.push_back(val);
    }
    res.push_back(cur);
    return res;
}

vector<string> split(typename string::const_iterator begin, typename string::const_iterator end, char val) {
    vector<string> res;
    string cur = "";
    for(auto it = begin; it != end; it++) {
        if(*it == val) {
            res.push_back(cur);
            cur.clear();
        } else cur.push_back(val);
    }
    res.push_back(cur);
    return res;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template <typename T>
pair<VI, vector<T>> compress(const vector<T> &a) {
    int n = a.size();
    vector<T> x;
    REP(i, n) x.push_back(a[i]);
    sort(ALL(x)); x.erase(unique(ALL(x)), x.end());
    VI res(n);
    REP(i, n) res[i] = lower_bound(ALL(x), a[i]) - x.begin();
    return make_pair(res, x);
}

template <typename T>
pair<vector<T>, vector<T>> factorial(int n) {
    vector<T> res(n+1), rev(n+1);
    res[0] = 1;
    REP(i, n) res[i+1] = res[i] * (i+1);
    rev[n] = 1 / res[n];
    for(int i = n; i > 0; i--) {
        rev[i-1] = rev[i] * i;
    }
    return make_pair(res, rev);
}
#line 3 "library/KowerKoint/internal_operator.hpp"

namespace internal_operator {
    template <typename T>
    T default_add(T a, T b) { return a + b; }
    template <typename T>
    T default_sub(T a, T b) { return a - b; }
    template <typename T>
    T zero() { return T(0); }
    template <typename T>
    T default_div(T a, T b) { return a / b; }
    template <typename T>
    T default_mult(T a, T b) { return a * b; }
    template <typename T>
    T one() { return T(1); }
    template <typename T>
    T default_xor(T a, T b) { return a ^ b; }
    template <typename T>
    T default_and(T a, T b) { return a & b; }
    template <typename T>
    T default_or(T a, T b) { return a | b; }
    ll mod3() { return 998244353LL; }
    ll mod7() { return 1000000007LL; }
    ll mod9() { return 1000000009LL; }
}

#line 3 "library/KowerKoint/integer.hpp"

VL divisor(ll n) {
    assert(n > 0);
    VL fow, bck;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            fow.push_back(i);
            if(i * i != n) bck.push_back(n / i);
        }
    }
    reverse(ALL(bck));
    fow.insert(fow.end(), ALL(bck));
    return fow;
}

bool is_prime(ll n) {
    assert(n > 0);
    for(ll d = 2; d*d <= n; d++) {
        if(n % d == 0) return false;
    }
    return true;
}

VL least_prime_factors(ll n) {
    assert(n > 0);
    VL lpfs(n+1, -1), primes;
    FOR(d, 2, n+1) {
        if(lpfs[d] == -1) {
            lpfs[d] = d;
            primes.push_back(d);
        }
        for(ll p : primes) {
            if(p * d > n || p > lpfs[d]) break;
            lpfs[p*d] = p;
        }
    }
    return lpfs;
}

VL prime_list(ll n) {
    assert(n > 0);
    VL primes;
    vector<bool> sieved(n+1);
    FOR(d, 2, n+1) {
        if(!sieved[d]) {
            primes.push_back(d);
            for(ll i = d*d; i <= n; i += d) sieved[i] = 1;
        }
    }
    return primes;
}

map<ll, int> prime_factor(ll n) {
    assert(n > 0);
    map<ll, int> factor;
    for(ll d = 2; d*d <= n; d++) {
        while(n%d == 0) {
            n /= d;
            factor[d]++;
        }
    }
    if(n > 1) factor[n]++;
    return factor;
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1, y = 0;
    ll nx = 0, ny = 1;
    while(b) {
        ll q = a / b;
        tie(a, b) = LP(b, a % b);
        tie(x, nx) = LP(nx, x - nx*q);
        tie(y, ny) = LP(ny, y - ny*q);
    }
    return a;
}

ll inv_mod(ll n, ll m) {
    ll x, y;
    assert(extgcd(n, m, x, y) == 1);
    x %= m;
    if(x < 0) x += m;
    return x;
}

ll pow_mod(ll a, ll n, ll m) {
    if(n == 0) return 1LL;
    if(n < 0) return inv_mod(pow_mod(a, -n, m), m);
    ll res = 1;
    while(n) {
        if(n & 1) {
            res *= a;
            res %= m;
        }
        n >>= 1;
        a *= a;
        a %= m;
    }
    return res;
}

#line 5 "library/KowerKoint/modint.hpp"

template <ll (*mod)()>
struct Modint {
    ll val;
    
    Modint(): val(0) {}

    Modint(ll x): val(x) {
        val %= mod();
        if(val < 0) val += mod();
    }

    Modint& operator+=(const Modint& r) {
        val += r.val;
        if(val >= mod()) val -= mod();
        return *this;
    }
    friend Modint operator+(const Modint& l, const Modint& r) {
        return Modint(l) += r;
    }

    Modint& operator-=(const Modint& r) {
        val -= r.val;
        if(val < 0) val += mod();
        return *this;
    }
    friend Modint operator-(const Modint& l, const Modint& r) {
        return Modint(l) -= r;
    }

    Modint& operator*=(const Modint& r) {
        val *= r.val;
        val %= mod();
        return *this;
    }
    Modint operator*(const Modint& r) {
        return (Modint(*this) *= r);
    }
    friend Modint operator*(const Modint& l, const Modint& r) {
        return Modint(l) *= r;
    }

    Modint pow(ll n) const {
        return Modint(pow_mod(val, n, mod()));
    }

    Modint inv() const {
        return Modint(inv_mod(val, mod()));
    }

    Modint& operator/=(const Modint& r) {
        return (*this *= r.inv());
    }
    friend Modint operator/(const Modint& l, const Modint& r) {
        return Modint(l) /= r;
    }

    Modint& operator^=(const ll n) {
        val = pow_mod(val, n, mod());
        return *this;
    }
    Modint operator^(const ll n) {
        return this->pow(n);
    }

    Modint operator+() const { return *this; }
    Modint operator-() const { return Modint() - *this; }

    Modint& operator++() {
        val++;
        if(val == mod()) val = 0LL;
        return *this;
    }
    Modint& operator++(int) {
        Modint res(*this);
        ++*this;
        return res;
    }

    Modint& operator--() {
        if(val == 0LL) val = mod();
        val--;
        return *this;
    }
    Modint& operator--(int) {
        Modint res(*this);
        --*this;
        return res;
    }

    friend bool operator==(const Modint& l, const Modint& r) {
        return l.val == r.val;
    }
    friend bool operator!=(const Modint& l, const Modint& r) {
        return l.val != r.val;
    }

    static pair<vector<Modint>, vector<Modint>> factorial(int n) {
        vector<Modint> fact(n+1), rfact(n+1);
        fact[0] = 1;
        REP(i, n) fact[i+1] = fact[i] * (i+1);
        rfact[n] = 1 / fact[n];
        for(int i = n-1; i >= 0; i--) rfact[i] = rfact[i+1] * (i+1);
        return {fact, rfact};
    }

    friend istream& operator>>(istream& is, Modint& mi) {
        is >> mi.val;
        return is;
    }

    friend ostream& operator<<(ostream& os, const Modint& mi) {
        os << mi.val;
        return os;
    }
};

using MI3 = Modint<internal_operator::mod3>;
using V3 = vector<MI3>;
using VV3 = vector<V3>;
using VVV3 = vector<VV3>;
using MI7 = Modint<internal_operator::mod7>;
using V7 = vector<MI7>;
using VV7 = vector<V7>;
using VVV7 = vector<VV7>;
using MI9 = Modint<internal_operator::mod9>;
using V9 = vector<MI9>;
using VV9 = vector<V9>;
using VVV9 = vector<VV9>;
#line 3 "library/KowerKoint/counting.hpp"

template <typename T>
struct Counting {
    vector<T> fact, ifact;

    Counting() {}
    Counting(ll n) {
        expand(n);
    }

    void expand(ll n) {
        ll sz = (ll)fact.size();
        if(sz > n) return;
        fact.resize(n+1);
        ifact.resize(n+1);
        fact[0] = 1;
        FOR(i, max(1LL, sz), n+1) fact[i] = fact[i-1] * i;
        ifact[n] = 1 / fact[n];
        for(ll i = n-1; i >= sz; i--) ifact[i] = ifact[i+1] * (i+1);
    }

    T permutation(ll n, ll r) {
        assert(n >= r);
        assert(r >= 0);
        expand(n);
        return fact[n] * ifact[n-r];
    }

    T combination(ll n, ll r) {
        assert(n >= r);
        assert(r >= 0);
        expand(n);
        return fact[n] * ifact[r] * ifact[n-r];
    }

    T stirling(ll n, ll k) {
        assert(n >= k);
        assert(k >= 0);
        if(n == 0) return 1;
        T res = 0;
        int sign = k%2? -1 : 1;
        expand(k);
        REP(i, k+1) {
            res += sign * ifact[i] * ifact[k-i] * T(i).pow(n);
            sign *= -1;
        }
        return res;
    }

    vector<vector<T>> stirling_table(ll n, ll k) {
        assert(n >= 0 && k >= 0);
        vector<vector<T>> res(n+1, vector<T>(k+1));
        res[0][0] = 1;
        FOR(i, 1, n+1) FOR(j, 1, k+1) {
            res[i][j] = res[i-1][j-1] + j * res[i-1][j];
        }
        return res;
    }

    T bell(ll n, ll k) {
        assert(n >= 0 && k >= 0);
        expand(k);
        vector<T> tmp(k+1);
        int sign = 1;
        tmp[0] = 1;
        FOR(i, 1, k+1) {
            sign *= -1;
            tmp[i] = tmp[i-1] + sign * ifact[i];
        }
        T res = 0;
        REP(i, k+1) {
            res += T(i).pow(n) * ifact[i] * tmp[k-i];
        }
        return res;
    }

    vector<vector<T>> partition_table(ll n) {
        assert(n >= 0);
        vector<vector<T>> res(n+1, vector<T>(n+1));
        REP(i, n+1) res[0][i] = 1;
        FOR(i, 1, n+1) FOR(j, 1, n+1) {
            res[i][j] = res[i][j-1] + (i<j? 0 : res[i-j][j]);
        }
        return res;
    }
};
#line 2 "Contests/Dummy/main.cpp"

/* #include "atcoder/all" */
/* using namespace atcoder; */
/* #include "KowerKoint/expansion/ac-library/all.hpp" */
#line 2 "library/KowerKoint/string.hpp"

#line 4 "library/KowerKoint/string.hpp"

template <typename It>
vector<int> kmp_table(It begin, It end) {
    int m = end - begin;
    vector<int> table(m);
    int j = 0;
    FOR(i, 1, m) {
        while(j > 0 && *(begin+i) != *(begin+j)) j = table[j-1];
        if(*(begin+i) == *(begin+j)) table[i] = ++j;
    }
    return table;
}

vector<int> kmp_table(string& t) {
    return kmp_table(ALL(t));
}

template <typename It>
vector<int> kmp_find(It s_begin, It s_end, It t_begin, It t_end, vector<int>& table) {
    int n = s_end - s_begin;
    int m = t_end - t_begin;
    vector<int> res;
    int j = 0;
    REP(i, n) {
        while(j > 0 && *(s_begin+i) != *(t_begin+j)) j = table[j-1];
        if(*(s_begin+i) == *(t_begin+j)) {
            if(++j == m) {
                res.push_back(i - (m-1));
                j = table[m-1];
            }
        }
    }
    return res;
}

vector<int> kmp_find(string& s, string& t, vector<int>& table) {
    return kmp_find(ALL(s), ALL(t), table);
}

template <typename T=char, T root_char='_', int hash_size=30>
struct Trie {
    struct Node {
        T c;
        unordered_map<char, Node*> nxt;
        Node* failure;
        vector<int> fullmatch_keyword_id;
        vector<int> suffixmatch_keyword_id;

        Node(T _c): c(_c) {
            nxt.reserve(30);
        }
    };

    Node* root;
    int keyword_id = 0;

    Trie() {
        root = new Node(root_char);
    }

    template <typename It>
    void add(It begin, It end, int keyword_id_) {
        Node* cursor = root;
        for(It it = begin; it != end; it++) {
            if(!cursor->nxt.count(*it)) cursor->nxt[*it] = new Node(*it);
            cursor = cursor->nxt[*it];
        }
        cursor->fullmatch_keyword_id.push_back(keyword_id_);
    }

    void add(const string& str, int keyword_id_=-1) {
        add(ALL(str), keyword_id_ == -1? keyword_id++ : keyword_id_);
    }

    void build_failure() {
        queue<Node*> que;
        for(auto [c, to] : root->nxt) {
            to->failure = root;
            for(int x : to->fullmatch_keyword_id) {
                to->suffixmatch_keyword_id.push_back(x);
            }
            que.push(to);
        }
        while(!que.empty()) {
            Node* from = que.front(); que.pop();
            for(auto [c, to] : from->nxt) {
                Node* cursor = from->failure;
                while(cursor != root && !cursor->nxt.count(c)) cursor = cursor->failure;
                if(cursor->nxt.count(c)) to->failure = cursor->nxt[c];
                else to->failure = root;
                for(int x : to->fullmatch_keyword_id) {
                    to->suffixmatch_keyword_id.push_back(x);
                }
                for(int x : to->failure->suffixmatch_keyword_id) {
                    to->suffixmatch_keyword_id.push_back(x);
                }
                que.push(to);
            }
        }
    }

    template <typename It>
    void aho_corasick(It begin, It end, function<void(vector<int>&)>& f) {
        Node* cursor = root;
        for(It it = begin; it != end; it++) {
            while(cursor != root && !cursor->nxt.count(*it)) cursor = cursor->failure;
            if(cursor->nxt.count(*it)) {
                cursor = cursor->nxt[*it];
                f(cursor->suffixmatch_keyword_id);
            }
        }
    }

    template <typename It>
    ll aho_corasick(It begin, It end) {
        ll res = 0;
        function<void(vector<int>&)> f = [&](vector<int>& v) {
            res += v.size();
        };
        aho_corasick(begin, end, f);
        return res;
    }

    void aho_corasick(string &s, function<void(vector<int>&)>& f) {
        aho_corasick(ALL(s), f);
    }

    ll aho_corasick(string &s) {
        return aho_corasick(ALL(s));
    }
};

template <typename T>
struct RollingHash {
    int num;
    vector<T> base;
    vector<vector<T>> power;

    RollingHash(vector<T> base_) : num(base_.size()), base(base_) {
        power = vector<vector<T>>(num, vector<T>(1, 1));
    }

    RollingHash(int num_=3) : num(num_) {
        assert(num_ > 0);
        power = vector<vector<T>>(num, vector<T>(1, 1));
        mt19937 engine((random_device){}());
        REP(i, num) base.push_back(engine());
    }

    void expand(int n) {
        int m = power[0].size();
        if(m > n) return;
        REP(i, num) {
            power[i].resize(n+1);
            FOR(j, m, n+1) power[i][j] = power[i][j-1] * base[i];
        }
    }

    template<typename It>
    vector<vector<T>> build(It begin, It end) {
        int n = end - begin;
        vector<vector<T>> res(num, vector<T>(n+1));
        REP(i, num) REP(j, n) {
            res[i][j+1] = res[i][j] * base[i] + *(begin+j);
        }
        return res;
    }

    vector<vector<T>> build(const string& s) {
        return build(ALL(s));
    }

    vector<T> query(const vector<vector<T>>& hash, int l, int r) {
        assert(hash.size() == num);
        assert(0 <= l && l <= r && r < hash[0].size());
        expand(r - l);
        vector<T> res(num);
        REP(i, num) res[i] = hash[i][r] - hash[i][l] * power[i][r-l];
        return res;
    }
};
#line 7 "Contests/Dummy/main.cpp"

void solve(){
    while([] {
        int n, m, p; cin >> n >> m >> p;
        if(!n) return false;
        VVI z(n, VI(n));
        VVVI col(n, VVI(n, VI(n)));
        auto judge = [&](int turn) {
            REP(i, n) REP(j, n) REP(k, n) {
                FOR(dx, -1, 2) FOR(dy, -1, 2) FOR(dz, -1, 2) {
                    if(dx == 0 && dy == 0 && dz == 0) continue;
                    int tx = i + (m-1) * dx;
                    int ty = j + (m-1) * dy;
                    int tz = k + (m-1) * dz;
                    if(tx < 0 || tx >= n || ty < 0 || ty >= n || tz < 0 || tz >= n) continue;
                    bool flag = true;
                    REP(s, m) {
                        flag &= col[i+dx*s][j+dy*s][k+dz*s] == turn;
                    }
                    if(flag) return true;
                }
            }
            return false;
        };
        int turn = 1;
        VP xy(p); cin >> xy;
        REP(i, p) {
            auto [x, y] = xy[i]; x--; y--;
            col[x][y][z[x][y]++] = turn;
            if(judge(turn)) {
                if(turn == 1) print("Black", i+1);
                else print("White", i+1);
                return true;;
            }
            turn = 3 - turn;
        }
        print("Draw");
        return true;
    }());
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    // Fasterize input/output script
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(100);
    // scanf/printf user should delete this fasterize input/output script

    int t = 1;
    //cin >> t; // comment out if solving multi testcase
    for(int testCase = 1;testCase <= t;++testCase){
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 3344
final_rank: 6

code_snippet: #line 1 "a.cpp"
#define PROBLEM ""
#line 2 "/home/kuhaku/atcoder/github/atcoder-lib/lib/template/atcoder.hpp"
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#line 2 "/home/kuhaku/atcoder/github/atcoder-lib/lib/template/template.hpp"
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool chmax(T &a, const U &b) {
    return a < b ? a = b, true : false;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
    return b < a ? a = b, true : false;
}
constexpr int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr int MOD = 1000000007;
constexpr int MOD_N = 998244353;
constexpr double EPS = 1e-7;
const double PI = acos(-1.0);
#line 6 "/home/kuhaku/atcoder/github/atcoder-lib/lib/template/atcoder.hpp"
using ll = int64_t;
using ld = long double;
#define FOR(i, m, n) for(int i = (m); i < int(n); ++i)
#define FORR(i, m, n) for(int i = (m)-1; i >= int(n); --i)
#define FORL(i, m, n) for(int64_t i = (m); i < int64_t(n); ++i)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FOR(i, 1, n+1)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n+1, 1)
#define all(s) (s).begin(), (s).end()
template<class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) { is >> p.first >> p.second; return is; }
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &i : v) is>>i; return is; }
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
    return os<<'('<<p.first<< ','<<p.second<<')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto it=v.begin(); it!=v.end(); ++it) { os<<(it==v.begin()?"":" ")<<*it; } return os;
}
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    if constexpr(sizeof...(tail)==0) std::cout<<head<<'\n'; else std::cout<<head<<' ',co(forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    if constexpr(sizeof...(tail)==0) std::cerr<<head<<'\n'; else std::cerr<<head<<' ',ce(forward<Tail>(tail)...);
}
template<typename T, typename... Args>
auto make_vector(T x, int arg, Args ...args) {
    if constexpr(sizeof...(args)==0) return std::vector<T>(arg,x); else return std::vector(arg,make_vector<T>(x,args...));
}
void sonic() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); }
void setp(const int n) { std::cout<<std::fixed<<std::setprecision(n); }
void Yes(bool is_correct) { std::cout<<(is_correct?"Yes":"No")<<std::endl; }
void YES(bool is_correct) { std::cout<<(is_correct?"YES":"NO")<<std::endl; }
#line 3 "a.cpp"

array<int, 3> arr = {0, 1, -1};

int main(void) {
    sonic();
    while (true) {
        int n, m, p;
        cin >> n >> m >> p;
        if (!n)
            break;
        vector<vector<int>> a(n, vector<int>(n));
        vector<tuple<int, int, int>> b, w;
        set<tuple<int, int, int>> bl, wh;
        bool flag = true;
        rep(_, p) {
            int x, y;
            cin >> x >> y;
            x--, y--;
            b.emplace_back(x, y, a[x][y]);
            bl.emplace(x, y, a[x][y]);
            if (!flag)
                continue;
            for (auto t : b) {
                FOR(i, 1, 27) {
                    int dx = arr[i % 3], dy = arr[i / 3 % 3], dz = arr[i / 9 % 3];
                    bool ok = true;
                    rep(j, m) {
                        ok &= bl.find(make_tuple(get<0>(t) + dx * j, get<1>(t) + dy * j,
                                                 get<2>(t) + dz * j)) != bl.end();
                    }
                    if (flag && ok) {
                        if (_ & 1)
                            cout << "White " << _ + 1 << endl;
                        else
                            cout << "Black " << _ + 1 << endl;
                        flag = false;
                    }
                }
            }
            a[x][y]++;

            swap(b, w);
            swap(bl, wh);
        }

        if (flag) {
            co("Draw");
        }
    }

    return 0;
}
accuracy: 1
time_ms: 1250
memory_kb: 3260
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;

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

bool calc(vector<vector<vector<int>>>tmp,int n,int m) {
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            for(int k = 0; k < tmp[i][j].size(); k++) {
                for(int l = 0; l < 13; l++) {
                    int cnt = 1;
                    int nx = i,ny = j,nz = k;
                    for(int r = 1; r < m; r++) {
                        nx += dx[l];
                        ny += dy[l];
                        nz += dz[l];
                        if(min({nx,ny,nz}) >= 0 && max(nx,ny) < n && nz < tmp[nx][ny].size()) {
                            if(tmp[nx-dx[l]][ny-dy[l]][nz-dz[l]] != tmp[nx][ny][nz]) {
                                break;
                            }
                            cnt++;
                        }
                        else {
                            break;
                        }
                    }
                    if(cnt == m) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}

int main() {
    while (true) {
        int n,m,p;
        cin >> n >> m >> p;
        if(n == 0 && m == 0 && p == 0) {
            return 0;
        }
        vector<vector<vector<int>>>tmp(n,vector<vector<int>>(n));
        bool flag = true;
        for(int i = 0; i < p; i++) {
            int x,y;
            cin >> x >> y;
            x--;
            y--;
            tmp[x][y].push_back(i%2);
            if(calc(tmp,n,m) && flag) {
                flag = false;
                cout << ((i%2 == 0)?"Black":"White") << " " << i+1 << endl;
            }
        }
        if(flag) {
            cout << "Draw" << endl;
        }
    }
}
accuracy: 1
time_ms: 120
memory_kb: 3448
final_rank: 11

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

vector<string> solve(int n,int m,int p){
    vector<pair<int,int>> a(p);
    rep(i,p){
        in(a[i]);
        a[i].first--,a[i].second--;
    }
    vector<vector<deque<int>>> A(n,vector<deque<int>>(n));
    //x,y,z,dx,dy,dz,color
    function<int(array<int,7>)> rec=[&](array<int,7> b){
        if(b[0]<0||b[0]>=n)return 0;
        if(b[1]<0||b[1]>=n)return 0;
        if(b[2]<0||b[2]>=A[b[0]][b[1]].size())return 0;
        if(b[6]!=A[b[0]][b[1]][b[2]])return 0;
        b[0]+=b[3],b[1]+=b[4],b[2]+=b[5];
        return 1+rec(b);
    };
    rep(i,p){
        if(i%2==0){
            A[a[i].first][a[i].second].push_back(0);
            int maxv=0;
            for(int dx=-1;dx<=1;dx++){
                for(int dy=-1;dy<=1;dy++){
                    for(int dz=-1;dz<=1;dz++){
                        if(!dx&&!dy&&!dz)continue;
                        array<int,7> c={a[i].first,a[i].second,(int)A[a[i].first][a[i].second].size()-1,
                        dx,dy,dz,0};
                        array<int,7> d={a[i].first,a[i].second,(int)A[a[i].first][a[i].second].size()-1,
                        -dx,-dy,-dz,0};
                        chmax(maxv,rec(c)+rec(d)-1);
                    }
                }
            }
            if(maxv>=m){
                return {"Black",to_string(i+1)};
            }
        }else{
            A[a[i].first][a[i].second].push_back(1);
            int maxv=0;
            for(int dx=-1;dx<=1;dx++){
                for(int dy=-1;dy<=1;dy++){
                    for(int dz=-1;dz<=1;dz++){
                        if(!dx&&!dy&&!dz)continue;
                        array<int,7> c={a[i].first,a[i].second,(int)A[a[i].first][a[i].second].size()-1,
                        dx,dy,dz,1};
                        array<int,7> d={a[i].first,a[i].second,(int)A[a[i].first][a[i].second].size()-1,
                        -dx,-dy,-dz,1};
                        chmax(maxv,rec(c)+rec(d)-1);
                    }
                }
            }
            if(maxv>=m){
                return {"White",to_string(i+1)};
            }
        }
    }
    return {"Draw"};
}

int main(){
    int n,m,p;
    while(cin>>n>>m>>p){
        if(!n)return 0;
        out(solve(n,m,p));
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3308
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int n, m, p;

bool check(vector<vector<vector<int>>>& game) {
    for (int x = 0; x < n; ++x) {
        for (int y = 0; y < n; ++y) {
            for (int z = 0; z < n; ++z) {
                vector<vector<int>> rows(13);
                for (int i = 0; i < m; ++i) {
                    if (x+i < n) rows[0].push_back(game[x+i][y][z]);
                    if (y+i < n) rows[1].push_back(game[x][y+i][z]);
                    if (z+i < n) rows[2].push_back(game[x][y][z+i]);
                    if (x+i < n && y+i < n) rows[3].push_back(game[x+i][y+i][z]);
                    if (y+i < n && z+i < n) rows[4].push_back(game[x][y+i][z+i]);
                    if (z+i < n && x+i < n) rows[5].push_back(game[x+i][y][z+i]);
                    if (x+i < n && y-i >= 0) rows[6].push_back(game[x+i][y-i][z]);
                    if (y+i < n && z-i >= 0) rows[7].push_back(game[x][y+i][z-i]);
                    if (z+i < n && x-i >= 0) rows[8].push_back(game[x-i][y][z+i]);

                    if (x+i < n && y+i < n && z+i < n) rows[9].push_back(game[x+i][y+i][z+i]);
                    if (x+i < n && y-i >= 0 && z+i < n) rows[10].push_back(game[x+i][y-i][z+i]);
                    if (x+i < n && y+i < n && z-i >= 0) rows[11].push_back(game[x+i][y+i][z-i]);
                    if (x+i < n && y-i >= 0 && z-i >= 0) rows[12].push_back(game[x+i][y-i][z-i]);
                }
                for (int i = 0; i < 13; ++i) {
                    if (rows[i].size() < m || rows[i][0] == -1) continue;
                    bool ok = true;
                    for (int j = 1; j < m; ++j) {
                        if (rows[i][0] != rows[i][j]) {
                            ok = false;
                            break;
                        }
                    }
                    if (ok) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    while (true) {
        cin >> n >> m >> p;
        if (n == 0 && m == 0 && p == 0) break;
        vector game(n, vector<vector<int>>(n, vector<int>(n, -1)));
        int winner = -1;
        int turn = 0;
        while (p--) {
            int x, y;
            cin >> x >> y;
            --x, --y;
            if (winner != -1) continue;
            int z = 0;
            while (game[x][y][z] != -1) ++z;
            game[x][y][z] = turn % 2;
            if (check(game)) {
                winner = turn % 2;
            }
            ++turn;
        }
        if (winner == 0) cout << "Black " << turn << "\n";
        else if (winner == 1) cout << "White " << turn << "\n";
        else cout << "Draw\n";
    }
}
accuracy: 1
time_ms: 1600
memory_kb: 3164
final_rank: 13

code_snippet: #include <bits/stdc++.h>
#include <time.h> 
using namespace std;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
vector<vector<int>> G;
vector<vector<int>> GR;
/*
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
*/

bool in(ll x,ll y, ll z,ll N){
    if(0<=x&&x<N&&0<=y&&y<N&&0<=z&&z<N)return true;
    return false;
}

vll dx={1,-1,0};
vll dy={1,-1,0};
vll dz={1,-1,0};
int main() {
    while(1){
        ll N,M,P;
        cin>>N>>M>>P;
        if(N==0)return 0;
        string AN="Draw";
        ll an=-1;
        ll k=0;
        vector<vector<vll>> B(N,vector<vll>(N,vll(N,-1)));
        rep(p,P){
            ll X,Y;
            cin>>X>>Y;
            X--;Y--;
            rep(i,N){
                if(B[X][Y][i]==-1){
                    B[X][Y][i]=k;
                    k=1-k;
                    break;
                }
            }

            rep(x,N)rep(y,N)rep(z,N){
                if(B[x][y][z]==0){
                    rep(i,3)rep(u,3)rep(e,3){
                        if(i+u+e==6)continue;
                        ll nx=x;
                        ll ny=y;
                        ll nz=z;
                        bool C=true;                        
                        rep(j,M){
                            
                            if(in(nx,ny,nz,N)){
                                if(B[nx][ny][nz]==0);
                                else C=false;
                            }
                            else C=false;
                            nx+=dx[i];
                            ny+=dy[u];
                            nz+=dz[e];
                        }
                        if(C){
                            if(AN=="Draw"){
                                AN="Black";
                                an=p+1;
                            }
                        }
                    }
                }
                else if(B[x][y][z]==1){
                     rep(i,3)rep(u,3)rep(e,3){
                         if(i+u+e==6)continue;
                        ll nx=x;
                        ll ny=y;
                        ll nz=z;
                        bool C=true;                        rep(j,M){
                            if(in(nx,ny,nz,N)){
                                if(B[nx][ny][nz]==1);
                                else C=false;
                            }
                            else C=false;
                            nx+=dx[i];
                            ny+=dy[u];
                            nz+=dz[e];
                        }
                        if(C){
                            if(AN=="Draw"){
                                AN="White";
                                an=p+1;
                            }
                        }
                    }
                }
            }




        }
        if(AN=="Draw")cout<<AN<<endl;
        else {
            cout<<AN<<" "<<an<<endl;
        }
    }
}
accuracy: 1
time_ms: 1820
memory_kb: 3380
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;

// clang-format off
//#include <atcoder/modint>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using vii = vector<int>;
using vll = vector<ll>;
using vdd = vector<ld>;
using vvii = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvdd = vector<vector<ld>>;
using vvvii = vector<vector<vector<int>>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvdd = vector<vector<vector<ld>>>;
template<class T, class U> using P = pair<T, U>;
template<class T> using V1 = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T> using V3 = vector<vector<vector<T>>>;
template<class T> using pque = priority_queue<T, vector<T>, greater<T>>;
#define _overload3(_1, _2, _3, name, ...) name
#define rep1(n) for (ll i = 0; i < (n); i++)
#define rep2(i, n) for (ll i = 0; i < (n); i++)
#define rep3(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(...) _overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for (ll i = (n) - 1; i >= 0; i--)
#define rrep2(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rrep3(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(...) _overload3(__VA_ARGS__, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define popcnt(x) __builtin_popcountll(x)
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end());
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const ld DINF = numeric_limits<ld>::infinity();
const ll mod = 1000000007;
//const ll mod = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;
//const ll dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const ll dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> T minV(const vector<T> &x) { return *min_element(all(x)); }
template<typename T> T maxV(const vector<T> &x) { return *max_element(all(x)); }
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.fi << ", " << p.se << ")"; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "[ "; for (auto &z : v) os << z << " "; os << "]"; return os; }
#ifdef _DEBUG
#define show(x) cout << #x << " = " << x << endl;
#else
#define show(x)
#endif
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll rem(ll a, ll b) { return (a % b + b) % b; }
// clang-format on

// using mint = modint998244353;
// using mint = modint1000000007;

ll modpow(ll a, ll N, ll mod) {
    ll res = 1;
    // 例えば3=101(2)なので、下位bitから順に1ならa倍する
    while (N) {
        if (N & 1) res = res * a % mod;
        a = a * a % mod;
        N >>= 1;
    }
    return res;
}

int seq(vii &c, int n, int m) {
    int cnt = 0;
    rep(i, n - 1) {
        if (c[i] == c[i + 1] && c[i] != -1)
            cnt++;
        else
            cnt = 0;
        if (cnt == m - 1) return 1;
    }
    return 0;
}
int dx[13] = {0, 0, 1, 0, 0, 1, 1, 1, -1, 1, 1, 1, -1};
int dy[13] = {0, 1, 0, 1, 1, 1, -1, 0, 0, 1, 1, -1, 1};
int dz[13] = {1, 0, 0, 1, -1, 0, 0, 1, 1, 1, -1, 1, 1};
int K = 13;

int win(vvvii &a, int n, int m) {
    rep(x, n) rep(y, n) rep(z, n) {
        vvii b(K);
        rep(k, K) {
            int cx = x, cy = y, cz = z;
            while (0 <= cx && cx < n && 0 <= cy && cy < n && 0 <= cz && cz < n) {
                b[k].pb(a[cx][cy][cz]);
                cx += dx[k];
                cy += dy[k];
                cz += dz[k];
            }
            if (seq(b[k], sz(b[k]), m)) return 1;
        }
    }
    return 0;
}

void solve(int n) {
    int m, p;
    cin >> m >> p;
    vvvii a(n, vvii(n, vii(n, -1)));
    vvii b(n, vii(n, 0));
    vii x(p), y(p);
    rep(p) {
        cin >> x[i] >> y[i];
        x[i]--, y[i]--;
    }
    rep(i, p) {
        a[x[i]][y[i]][b[x[i]][y[i]]] = i % 2;
        b[x[i]][y[i]]++;
        if (win(a, n, m)) {
            cout << ((i % 2 == 0) ? "Black " : "White ") << i + 1 << endl;
            return;
        }
    }
    cout << "Draw" << endl;
    return;
}

int main() {
    vii x = {-1, -1, -1, 0, 0, 1, 1, 0, 0};
    show(seq(x, sz(x), 3));
    int n;
    while (cin >> n, n) solve(n);
    return 0;
}

/*
メモ
実装実装実装
*/
accuracy: 1
time_ms: 1870
memory_kb: 3388
final_rank: 20

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int n,m,p, board[9][9][9], h[9][9];
vector<tuple<int,int,int>> v;

bool add(int a) {
    rep(i,n)rep(j,n)rep(k,n)for(auto d : v) {
        bool ok = true;
        int x = i, y = j, z = k;
        rep(l,m) {
            ok &= (0 <= x && x < n);
            ok &= (0 <= y && y < n);
            ok &= (0 <= z && z < n);
            if(!ok) break;
            ok &= (board[x][y][z] == a);
            int dx, dy, dz; tie(dx, dy, dz) = d;
            x += dx; y += dy; z += dz;
        }
        if(ok) return true;
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    rep(i,3)rep(j,3)rep(k,3)
        if(i != 1 || j != 1 || k != 1) 
            v.push_back({i - 1, j - 1, k - 1});

    while(true) {
        cin >> n >> m >> p; if(n == 0) break;
        rep(i,n)rep(j,n)rep(k,n) board[i][j][k] = 0;
        rep(i,n)rep(j,n) h[i][j] = 0;
        bool finish = false;
        rep(i,p) {
            int x,y; cin >> x >> y; x--; y--;
            board[x][y][h[x][y]++] = (i & 1) + 1;
            if(!finish && add((i & 1) + 1)) {
                cout << (i & 1 ? "White " : "Black ") << i + 1 << endl;
                finish = true;
            }
        }
        if(!finish) cout << "Draw" << endl;
    }
}
accuracy: 1
time_ms: 280
memory_kb: 3440
final_rank: 14

code_snippet: #pragma region Macros
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;

void Case(int i) { cout << "Case #" << i << ": "; }
int popcount(int x) { return __builtin_popcount(x); }
ll popcount(ll x) { return __builtin_popcountll(x); }
#pragma endregion Macros

int N, M, P;
int board[10][10][10];
int pointers[10][10];

int check() {
    auto is_in = [&](int n) -> bool {
        return (0 <= n and n < N);
    };
    auto ff = [&](int sx, int sy, int sz, int dx, int dy, int dz) -> int {
        set<int> se;
        REP(i, M) {
            int x = sx + i * dx;
            int y = sy + i * dy;
            int z = sz + i * dz;
            if(!is_in(x) or !is_in(y) or !is_in(z)) return -1;
            if(board[x][y][z] == -1) return -1;
            se.insert(board[x][y][z]);
        }
        if(se.size() != 1) return -1;
        return (*se.begin());
    };
    REP(sx, N) REP(sy, N) REP(sz, N) FOR(dx, -1, 2) FOR(dy, -1, 2) FOR(dz, -1, 2) {
        if(dx == 0 and dy == 0 and dz == 0) continue;
        int res = ff(sx, sy, sz, dx, dy, dz);
        if(res == -1) continue;
        return res;
    }
    return -1;
}

bool solve() {
    cin >> N >> M >> P;
    if(N == 0) return false;

    // reset params
    memset(board, -1, sizeof(board));
    memset(pointers, 0, sizeof(pointers));

    // enter board param
    REP(i, P) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        board[x][y][pointers[x][y]] = (i & 1);
        pointers[x][y]++;
        int res = check();
        if(res != -1) {
            REP(rest, P - i - 1) {
                cin >> x >> y;
            }
            cout << (res == 0 ? "Black " : "White ");
            cout << i+1 << "\n";
            return true;
        }
    }
    cout << "Draw\n";
    return true;
}

int main() {
    while(solve());
}
accuracy: 1
time_ms: 1090
memory_kb: 3152
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

int n,m,p;
int d[9][9][9],e[9][9][9],h[9][9];
struct r3{
  int x,y,z;
};
vector<r3> V;
bool f(int a){
  return 0<=a&&a<n;
}
bool fin(int a){
  REP(i,n)REP(j,n)REP(k,n)for(auto D:V){
    bool ok=true;
    int x=i,y=j,z=k;
    REP(l,m){
      ok&=f(x)&&f(y)&&f(z)&&d[x][y][z]==a;
      x+=D.x;y+=D.y;z+=D.z;
    }
    if(ok)return true;
  }
  return false;
}

int main(){
  REP(x,3)REP(y,3)REP(z,3)if(x!=1||y!=1||z!=1)V.push_back({x-1,y-1,z-1});
  while(cin>>n>>m>>p,n){
    REP(i,n)REP(j,n)REP(k,n)d[i][j][k]=0;
    REP(i,n)REP(j,n)h[i][j]=0;
    bool owari=false;
    REP(t,p){
      int x,y;cin>>x>>y;x--;y--;
      d[x][y][h[x][y]++]=(t&1)+1;
      if(!owari&&fin((t&1)+1)){
        if(t&1)cout<<"White "<<t+1<<endl;
        else cout<<"Black "<<t+1<<endl;
        owari=true;
      }
    }
    if(!owari)cout<<"Draw"<<endl;
  }
}
accuracy: 1
time_ms: 970
memory_kb: 3380
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int N, M, P;
    while (cin >> N >> M >> P, N) {
        vector table(N, vector(N, vector(N, -1)));  // -1:empty, 0:black, 1:white
        vector height(N, vector(N, 0));
        vector<int> X(P), Y(P);
        for (int i = 0; i < P; i++) {
            cin >> X[i] >> Y[i];
            X[i]--;
            Y[i]--;
        }

        const int d[3] = {-1, 0, 1};
        auto check_in = [&](int x, int y, int z) {
            return x == clamp(x, 0, N - 1) && y == clamp(y, 0, N - 1) && z == clamp(z, 0, N - 1);
        };
        auto check_win = [&](int player) {
            for (int x_start = 0; x_start < N; x_start++) {
                for (int y_start = 0; y_start < N; y_start++) {
                    for (int z_start = 0; z_start < N; z_start++) {
                        for (int x_idx = 0; x_idx < 3; x_idx++) {
                            for (int y_idx = 0; y_idx < 3; y_idx++) {
                                for (int z_idx = 0; z_idx < 3; z_idx++) {
                                    if (x_idx == 1 && y_idx == 1 && z_idx == 1)
                                        continue;
                                    bool flag = true;
                                    for (int i = 0; i < M; i++) {
                                        int x = x_start + i * d[x_idx];
                                        int y = y_start + i * d[y_idx];
                                        int z = z_start + i * d[z_idx];
                                        if (!check_in(x, y, z) || table[x][y][z] != player) {
                                            flag = false;
                                            break;
                                        }
                                    }
                                    if (flag) {
                                        return true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return false;
        };

        int winner = -1, moves = 0;
        for (int i = 0; i < P; i++) {
            int x = X[i], y = Y[i];
            int z = height[x][y];
            table[x][y][z] = i % 2;
            height[x][y]++;
            if (check_win(i % 2)) {
                winner = i % 2;
                moves = i + 1;
                break;
            }
        }
        if (winner == -1)
            cout << "Draw" << endl;
        else
            cout << (winner == 0 ? "Black" : "White") << " " << moves << endl;
    }
}
accuracy: 1
time_ms: 270
memory_kb: 3344
final_rank: 8