#include <bits/stdc++.h>
using namespace std;
char board[3][3];
int cross, nought;
bool cross_win() {
  if (board[0][0] == 'X' && board[0][1] == 'X' && board[0][2] == 'X')
    return true;
  if (board[1][0] == 'X' && board[1][1] == 'X' && board[1][2] == 'X')
    return true;
  if (board[2][0] == 'X' && board[2][1] == 'X' && board[2][2] == 'X')
    return true;
  if (board[0][0] == 'X' && board[1][0] == 'X' && board[2][0] == 'X')
    return true;
  if (board[0][1] == 'X' && board[1][1] == 'X' && board[2][1] == 'X')
    return true;
  if (board[0][2] == 'X' && board[1][2] == 'X' && board[2][2] == 'X')
    return true;
  if (board[0][0] == 'X' && board[1][1] == 'X' && board[2][2] == 'X')
    return true;
  if (board[0][2] == 'X' && board[1][1] == 'X' && board[2][0] == 'X')
    return true;
  return false;
}
bool nought_win() {
  if (board[0][0] == '0' && board[0][1] == '0' && board[0][2] == '0')
    return true;
  if (board[1][0] == '0' && board[1][1] == '0' && board[1][2] == '0')
    return true;
  if (board[2][0] == '0' && board[2][1] == '0' && board[2][2] == '0')
    return true;
  if (board[0][0] == '0' && board[1][0] == '0' && board[2][0] == '0')
    return true;
  if (board[0][1] == '0' && board[1][1] == '0' && board[2][1] == '0')
    return true;
  if (board[0][2] == '0' && board[1][2] == '0' && board[2][2] == '0')
    return true;
  if (board[0][0] == '0' && board[1][1] == '0' && board[2][2] == '0')
    return true;
  if (board[0][2] == '0' && board[1][1] == '0' && board[2][0] == '0')
    return true;
  return false;
}
int main() {
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      cin >> board[i][j];
      if (board[i][j] == 'X') cross++;
      if (board[i][j] == '0') nought++;
    }
  if (cross - nought > 1 || nought > cross) {
    printf("illegal");
    return 0;
  }
  if (cross_win()) {
    if (nought >= cross)
      printf("illegal");
    else
      printf("the first player won");
    return 0;
  }
  if (nought_win()) {
    if (cross > nought)
      printf("illegal");
    else
      printf("the second player won");
    return 0;
  }
  if (cross + nought == 9) {
    printf("draw");
    return 0;
  }
  if (cross - nought == 1) {
    printf("second");
    return 0;
  }
  if (cross == nought) {
    printf("first");
    return 0;
  }
  return 0;
}
