#include <bits/stdc++.h>
using namespace std;
int form[9], piece[9][2];
map<int, int> res;
string result[] = {
    "illegal", "the first player won", "the second player won", "draw", "first",
    "second"};
void pre() {
  form[0] = 3;
  piece[0][0] = 1;
  piece[0][1] = 1 << 1;
  for (int i = 1; i < 9; i++) {
    form[i] = form[i - 1] << 2;
    piece[i][0] = piece[i - 1][0] << 2;
    piece[i][1] = piece[i - 1][1] << 2;
  }
}
int add(int now, int p, int who, bool end) {
  int px = p / 3 * 3, py = p % 3;
  if ((piece[px][who] & now) && (piece[px + 1][who] & now) &&
      (piece[px + 2][who] & now))
    return who + 1;
  if ((piece[py][who] & now) && (piece[py + 3][who] & now) &&
      (piece[py + 6][who] & now))
    return who + 1;
  if ((p == 0 || p == 4 || p == 8) && (piece[0][who] & now) &&
      (piece[4][who] & now) && (piece[8][who] & now))
    return who + 1;
  if ((p == 2 || p == 4 || p == 6) && (piece[2][who] & now) &&
      (piece[4][who] & now) && (piece[6][who] & now))
    return who + 1;
  return end ? 3 : 5 - who;
}
void enumeration(int now, int who, int round) {
  for (int p = 0; p < 9; p++) {
    if (now & form[p]) continue;
    now ^= piece[p][who];
    if (!res[now]) {
      res[now] = add(now, p, who, round == 9);
      if (res[now] > 3) enumeration(now, who ^ 1, round + 1);
    }
    now ^= piece[p][who];
  }
}
int main() {
  int now = 0;
  char ch;
  pre();
  enumeration(now, 0, 1);
  for (int p = 0; p < 9; p++) {
    cin >> ch;
    if (ch == 'X')
      now ^= piece[p][0];
    else if (ch == '0')
      now ^= piece[p][1];
  }
  cout << result[res[now]] << endl;
  return 0;
}
