#include <bits/stdc++.h>
using namespace std;
char chessboard[10][10];
int x[10], y[10], z[10];
int a, b, c, d, e, f;
int first, second;
int main() {
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) {
      cin >> chessboard[i][j];
      if (chessboard[i][j] == 'X') a++;
      if (chessboard[i][j] == '0') b++;
    }
  if (b > a || a - b > 1) {
    printf("illegal");
    return 0;
  }
  for (int i = 1; i <= 3; i++)
    if (chessboard[i][1] == chessboard[i][2] &&
        chessboard[i][1] == chessboard[i][3] && chessboard[i][1] == 'X')
      x[i] = 1;
    else if (chessboard[i][1] == chessboard[i][2] &&
             chessboard[i][1] == chessboard[i][3] && chessboard[i][1] == '0')
      x[i] = 2;
  for (int i = 1; i <= 3; i++)
    if (chessboard[1][i] == chessboard[2][i] &&
        chessboard[1][i] == chessboard[3][i] && chessboard[1][i] == 'X')
      y[i] = 1;
    else if (chessboard[1][i] == chessboard[2][i] &&
             chessboard[1][i] == chessboard[3][i] && chessboard[1][i] == '0')
      y[i] = 2;
  if (chessboard[1][1] == chessboard[2][2] &&
      chessboard[3][3] == chessboard[1][1] && chessboard[1][1] == 'X')
    z[1] = 1;
  else if (chessboard[2][2] == chessboard[1][1] &&
           chessboard[1][1] == chessboard[3][3] && chessboard[1][1] == '0')
    z[1] = 2;
  if (chessboard[1][3] == chessboard[2][2] &&
      chessboard[3][1] == chessboard[1][3] && chessboard[1][3] == 'X')
    z[2] = 1;
  else if (chessboard[2][2] == chessboard[1][3] &&
           chessboard[3][1] == chessboard[1][3] && chessboard[1][3] == '0')
    z[2] = 2;
  for (int i = 1; i <= 3; i++)
    if (x[i] == 1)
      c++;
    else if (x[i] == 2)
      d++;
  for (int i = 1; i <= 3; i++)
    if (y[i] == 1)
      c++;
    else if (y[i] == 2)
      d++;
  for (int i = 1; i <= 2; i++)
    if (z[i] == 1)
      c++;
    else if (z[i] == 2)
      d++;
  if (c > 0 && d > 0) {
    printf("illegal");
    return 0;
  }
  if (c == 1 || c == 2) first = 1;
  if (d == 1 || d == 2) second = 1;
  if (first == 1 && second == 1) {
    printf("illegal");
    return 0;
  }
  if (second == 1 && a - b == 1) {
    printf("illegal");
    return 0;
  }
  if (first == 1 && a == b) {
    printf("illegal");
    return 0;
  }
  if (first == 1) {
    printf("the first player won");
    return 0;
  }
  if (second == 1) {
    printf("the second player won");
    return 0;
  }
  if (a + b == 9) {
    printf("draw");
    return 0;
  }
  if (a == b)
    printf("first");
  else
    printf("second");
}
