#include <bits/stdc++.h>
const int k[8] = {73, 146, 292, 7, 56, 448, 273, 84};
int T;
char s[15];
enum res { INVALID, X_WIN, O_WIN, X_TURN, O_TURN, DRAW };
inline int check(char c) {
  int x = 0;
  for (int i = 0; i < 9; ++i)
    if (s[i] == c) x |= 1 << i;
  for (int i = 0; i < 8; ++i)
    if ((x & k[i]) == k[i]) return 1;
  return 0;
}
inline res solve() {
  int i, x = 0, o = 0, X, O, t;
  for (i = 0; i < 3; ++i) scanf("%s", s + i * 3);
  for (i = 0; i < 9; ++i) {
    if (s[i] == 'X') ++x;
    if (s[i] == '0') ++o;
  }
  t = x - o;
  if (t != 0 && t != 1) return INVALID;
  X = check('X');
  O = check('0');
  if ((X && !t) || (O && t)) return INVALID;
  if (X) return X_WIN;
  if (O) return O_WIN;
  if (x + o == 9) return DRAW;
  return t ? O_TURN : X_TURN;
}
int main() {
  switch (solve()) {
    case INVALID:
      puts("illegal");
      break;
    case X_WIN:
      puts("the first player won");
      break;
    case O_WIN:
      puts("the second player won");
      break;
    case X_TURN:
      puts("first");
      break;
    case O_TURN:
      puts("second");
      break;
    case DRAW:
      puts("draw");
      break;
  }
  return 0;
}
