#include <bits/stdc++.h>
using namespace std;
char board[4][4];
int main() {
  for (int i = 0; i < 3; i++) cin >> board[i];
  int cntx, cnt0, won1, won2;
  cntx = cnt0 = won1 = won2 = 0;
  int wintimes = 0;
  char winplayer;
  for (int i = 0; i < 3; i++) {
    int j, winr = -1, winc = -1;
    char lastr, lastc;
    for (j = 0; j < 3; j++) {
      if (j && board[i][j] != lastr) winr = 0;
      if (j && board[j][i] != lastc) winc = 0;
      if (board[i][j] == 'X') cntx++;
      if (board[i][j] == '0') cnt0++;
      lastr = board[i][j];
      lastc = board[j][i];
    }
    if (winr == -1 && lastr != '.') {
      winplayer = lastr;
      lastr == 'X' ? won1 = 1 : won2 = 1;
      wintimes++;
    }
    if (winc == -1 && lastc != '.') {
      winplayer = lastc;
      lastc == 'X' ? won1 = 1 : won2 = 1;
      wintimes++;
    }
  }
  if (board[0][0] == board[1][1] && board[0][0] == board[2][2] &&
      board[1][1] != '.') {
    wintimes++;
    winplayer = board[1][1];
    winplayer == 'X' ? won1 = 1 : won2 = 1;
  }
  if (board[0][2] == board[1][1] && board[1][1] == board[2][0] &&
      board[1][1] != '.') {
    wintimes++;
    winplayer = board[1][1];
    winplayer == 'X' ? won1 = 1 : won2 = 1;
  }
  if (wintimes >= 2 && (won1 && won2 || won1 && cntx == 3 * wintimes ||
                        won2 && cnt0 == 3 * wintimes) ||
      cnt0 > cntx || cntx - cnt0 >= 2)
    cout << "illegal" << endl;
  else if (wintimes == 1 || wintimes == 2) {
    if (winplayer == 'X' && cntx <= cnt0) {
      cout << "illegal" << endl;
      return 0;
    }
    if (winplayer == '0' && cnt0 < cntx) {
      cout << "illegal" << endl;
      return 0;
    }
    winplayer == 'X' ? cout << "the first player won" << endl
                     : cout << "the second player won" << endl;
  } else {
    if (cnt0 + cntx == 9) {
      cout << "draw" << endl;
      return 0;
    }
    if (cnt0 == cntx)
      cout << "first" << endl;
    else
      cout << "second" << endl;
  }
  return 0;
}
