#include <bits/stdc++.h>
char board[3][1000];
int win() {
  int i;
  int win1, win2;
  win1 = win2 = 0;
  for (i = 0; i < 3; i++)
    if (board[i][0] == board[i][1] && board[i][1] == board[i][2]) {
      if (board[i][0] == 'X') {
        win1++;
      }
      if (board[i][0] == '0') {
        win2++;
      }
    }
  for (i = 0; i < 3; i++)
    if (board[0][i] == board[1][i] && board[1][i] == board[2][i]) {
      if (board[0][i] == 'X') {
        win1++;
      }
      if (board[0][i] == '0') {
        win2++;
      }
    }
  if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) {
    if (board[0][0] == 'X') {
      win1++;
    }
    if (board[0][0] == '0') {
      win2++;
    }
  }
  if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) {
    if (board[0][2] == 'X') {
      win1++;
    }
    if (board[0][2] == '0') {
      win2++;
    }
  }
  if (win1 && win2)
    return -1;
  else if (win1)
    return 1;
  else if (win2)
    return 2;
  return 0;
}
int main() {
  int v, s1, s2, i, j;
  bool ok;
  for (i = 0; i < 3; i++) gets(board[i]);
  if (strlen(board[0]) != 3 || strlen(board[1]) != 3 || strlen(board[2]) != 3) {
    printf("illegal\n");
    return 0;
  }
  s1 = 0;
  s2 = 0;
  ok = true;
  for (i = 0; i < 3; i++)
    for (j = 0; j < 3; j++) {
      if (board[i][j] == 'X')
        s1++;
      else if (board[i][j] == '0')
        s2++;
      else if (board[i][j] != '.')
        ok = false;
    }
  if (!ok || s1 < s2 || s1 > s2 + 1)
    printf("illegal\n");
  else {
    v = win();
    if (v < 0)
      printf("illegal\n");
    else if (v == 1) {
      if (s1 == s2)
        printf("illegal\n");
      else
        printf("the first player won\n");
    } else if (v == 2) {
      if (s1 > s2)
        printf("illegal\n");
      else
        printf("the second player won\n");
    } else if (s1 + s2 == 9)
      printf("draw\n");
    else {
      if ((s1 + s2) % 2 == 0)
        printf("first\n");
      else
        printf("second\n");
    }
  }
  return 0;
}
