#include <bits/stdc++.h>
using namespace std;
int winningCheck(vector<vector<char>>& board, char toCheck) {
  bool final_check = false;
  for (int i = 0; i < 3; i++) {
    bool cur_check = true;
    for (int j = 0; j < 3; j++) {
      cur_check &= (board[i][j] == toCheck);
    }
    if (cur_check) {
      if (final_check) {
        return -1;
      } else {
        final_check = true;
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    bool cur_check = true;
    for (int j = 0; j < 3; j++) {
      cur_check &= (board[j][i] == toCheck);
    }
    if (cur_check) {
      if (final_check) {
        return -1;
      } else {
        final_check = true;
      }
    }
  }
  bool cur_check = true;
  for (int i = 0; i < 3; i++) {
    cur_check &= (board[i][i] == toCheck);
  }
  if (cur_check) {
    if (final_check) {
      return -1;
    } else {
      final_check = true;
    }
  }
  cur_check = true;
  for (int i = 0; i < 3; i++) {
    cur_check &= (board[i][2 - i] == toCheck);
  }
  if (cur_check) {
    if (final_check) {
      return -1;
    } else {
      final_check = true;
    }
  }
  if (final_check) {
    return 1;
  } else {
    return 0;
  }
}
int main() {
  char cur;
  int counterX = 0, counter0 = 0;
  vector<vector<char>> board;
  for (int i = 0; i < 3; i++) {
    vector<char> cur_line;
    for (int j = 0; j < 4; j++) {
      if (j == 3) {
        scanf("%c", &cur);
        continue;
      }
      scanf("%c", &cur);
      if (cur == 'X') {
        counterX += 1;
      } else if (cur == '0') {
        counter0 += 1;
      }
      cur_line.push_back(cur);
    }
    board.push_back(cur_line);
  }
  int winnerX = winningCheck(board, 'X');
  int winner0 = winningCheck(board, '0');
  if (winnerX == 1 && winner0 == 1) {
    cout << "illegal" << endl;
  } else if (counter0 > counterX) {
    cout << "illegal" << endl;
  } else if (abs(counterX - counter0) >= 2) {
    cout << "illegal" << endl;
  } else if ((winner0 == 1 || winner0 == -1) && counterX > counter0) {
    cout << "illegal" << endl;
  } else if ((winnerX == 1 || winnerX == -1) && counterX == counter0) {
    cout << "illegal" << endl;
  } else if (winnerX == 1 || winnerX == -1) {
    cout << "the first player won" << endl;
  } else if (winner0 == 1 || winner0 == -1) {
    cout << "the second player won" << endl;
  } else if (counter0 + counterX == 9) {
    cout << "draw" << endl;
  } else if (counter0 == counterX) {
    cout << "first" << endl;
  } else if (counter0 < counterX) {
    cout << "second" << endl;
  }
  return 0;
}
