#include <bits/stdc++.h>
using namespace std;
char board[5][5];
int main() {
  scanf("%s%s%s", board[1] + 1, board[2] + 1, board[3] + 1);
  int cntX = 0, cnt0 = 0;
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++)
      if (board[i][j] == 'X')
        cntX++;
      else if (board[i][j] == '0')
        cnt0++;
  if (!(cntX == cnt0 || cntX == cnt0 + 1)) {
    cout << "illegal\n";
    return 0;
  }
  int win1 = false, win2 = false;
  for (int i = 1; i <= 3; i++) {
    if (board[i][1] == board[i][2] && board[i][2] == board[i][3] &&
        board[i][1] != '.') {
      if (board[i][1] == 'X')
        win1 = true;
      else
        win2 = true;
    }
    if (board[1][i] == board[2][i] && board[2][i] == board[3][i] &&
        board[1][i] != '.') {
      if (board[2][i] == 'X')
        win1 = true;
      else
        win2 = true;
    }
  }
  if (board[1][1] == board[2][2] && board[2][2] == board[3][3] &&
      board[1][1] != '.') {
    if (board[1][1] == 'X')
      win1 = true;
    else
      win2 = true;
  }
  if (board[3][1] == board[2][2] && board[2][2] == board[1][3] &&
      board[1][3] != '.') {
    if (board[1][3] == 'X')
      win1 = true;
    else
      win2 = true;
  }
  if ((win1 && cnt0 == cntX) || (win2 && cnt0 < cntX) || (win1 && win2)) {
    cout << "illegal\n";
    return 0;
  }
  if (win1) {
    cout << "the first player won\n";
    return 0;
  }
  if (win2) {
    cout << "the second player won\n";
    return 0;
  }
  if (cnt0 + cntX == 9) {
    cout << "draw\n";
    return 0;
  }
  if (cnt0 == cntX)
    cout << "first\n";
  else
    cout << "second\n";
  return 0;
}
