#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, l, n = 0, m = 0, q, w;
  char a[4][4];
  for (i = 1; i <= 3; i++)
    for (j = 1; j <= 3; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'X') n++;
      if (a[i][j] == '0') m++;
    }
  if (n >= m + 2 || m >= n + 2 || n + m == 0 || n < m) {
    cout << "illegal";
    exit(0);
  }
  if (a[1][1] == 'X' && a[1][2] == 'X' && a[1][3] == 'X' ||
      a[2][1] == 'X' && a[2][2] == 'X' && a[2][3] == 'X' ||
      a[3][1] == 'X' && a[3][2] == 'X' && a[3][3] == 'X' ||
      a[1][1] == 'X' && a[2][1] == 'X' && a[3][1] == 'X' ||
      a[1][2] == 'X' && a[2][2] == 'X' && a[3][2] == 'X' ||
      a[1][3] == 'X' && a[2][3] == 'X' && a[3][3] == 'X' ||
      a[1][1] == 'X' && a[2][2] == 'X' && a[3][3] == 'X' ||
      a[3][1] == 'X' && a[2][2] == 'X' && a[1][3] == 'X') {
    if (a[1][1] == '0' && a[1][2] == '0' && a[1][3] == '0' ||
        a[2][1] == '0' && a[2][2] == '0' && a[2][3] == '0' ||
        a[3][1] == '0' && a[3][2] == '0' && a[3][3] == '0' ||
        a[1][1] == '0' && a[2][1] == '0' && a[3][1] == '0' ||
        a[1][2] == '0' && a[2][2] == '0' && a[3][2] == '0' ||
        a[1][3] == '0' && a[2][3] == '0' && a[3][3] == '0' ||
        a[1][1] == '0' && a[2][2] == '0' && a[3][3] == '0' ||
        a[3][1] == '0' && a[2][2] == '0' && a[1][3] == '0') {
      cout << "illegal";
      exit(0);
    }
    {
      if (n <= m) {
        cout << "illegal";
        exit(0);
      }
      cout << "the first player won";
      exit(0);
    }
  }
  if (a[1][1] == '0' && a[1][2] == '0' && a[1][3] == '0' ||
      a[2][1] == '0' && a[2][2] == '0' && a[2][3] == '0' ||
      a[3][1] == '0' && a[3][2] == '0' && a[3][3] == '0' ||
      a[1][1] == '0' && a[2][1] == '0' && a[3][1] == '0' ||
      a[1][2] == '0' && a[2][2] == '0' && a[3][2] == '0' ||
      a[1][3] == '0' && a[2][3] == '0' && a[3][3] == '0' ||
      a[1][1] == '0' && a[2][2] == '0' && a[3][3] == '0' ||
      a[3][1] == '0' && a[2][2] == '0' && a[1][3] == '0') {
    if (n > m) {
      cout << "illegal";
      exit(0);
    }
    cout << "the second player won";
    exit(0);
  }
  if (n == m) {
    cout << "first";
    exit(0);
  }
  if (n - 1 == m && n + m < 9) {
    cout << "second";
    exit(0);
  }
  if (n + m == 9) {
    cout << "draw";
    exit(0);
  }
}
