#include <bits/stdc++.h>
using namespace std;
char a[1000][1000];
int main() {
  int x = 0, o = 0, d = 0, x1 = 0, o1 = 0, d1 = 0, d2 = 0, x2 = 0, o2 = 0;
  int i, j;
  for (j = 0; j < 3; ++j)
    for (i = 0; i < 3; ++i) {
      cin >> a[i][j];
      if (a[i][j] == '.') d++;
      if (a[i][j] == 'X') x++;
      if (a[i][j] == '0') o++;
    }
  if (d == 9) {
    cout << "illegal";
    return 0;
  }
  if (o > x) {
    cout << "illegal";
    return 0;
  }
  if (x >= o + 2) {
    cout << "illegal";
    return 0;
  } else {
    for (j = 0; j < 3; ++j) {
      for (i = 0; i < 3; ++i) {
        if (a[i][j] == a[i + 1][j] && a[i][j] == a[i + 2][j] &&
            a[i][j] == 'X') {
          if (o == x) {
            cout << "illegal";
            return 0;
          }
          cout << "the first player won";
          return 0;
        }
        if (a[i][j] == a[i][j + 1] && a[i][j] == a[i][j + 2] &&
            a[i][j] == 'X') {
          if (o == x) {
            cout << "illegal";
            return 0;
          }
          cout << "the first player won";
          return 0;
        }
        if (a[i][j] == a[i + 1][j + 1] && a[i][j] == a[i + 2][j + 2] &&
            a[i][j] == 'X') {
          if (o == x) {
            cout << "illegal";
            return 0;
          }
          cout << "the first player won";
          return 0;
        }
        if (a[i][j] == a[i + 1][j - 1] && a[i][j] == a[i + 2][j - 2] &&
            a[i][j] == 'X') {
          if (o == x) {
            cout << "illegal";
            return 0;
          }
          cout << "the first player won";
          return 0;
        }
        if (a[i][j] == a[i + 1][j] && a[i][j] == a[i + 2][j] &&
            a[i][j] == '0') {
          if (o < x) {
            cout << "illegal";
            return 0;
          }
          cout << "the second player won";
          return 0;
        }
        if (a[i][j] == a[i][j + 1] && a[i][j] == a[i][j + 2] &&
            a[i][j] == '0') {
          if (o < x) {
            cout << "illegal";
            return 0;
          }
          cout << "the second player won";
          return 0;
        }
        if (a[i][j] == a[i + 1][j + 1] && a[i][j] == a[i + 2][j + 2] &&
            a[i][j] == '0') {
          if (o < x) {
            cout << "illegal";
            return 0;
          }
          cout << "the second player won";
          return 0;
        }
        if (a[i][j] == a[i + 1][j - 1] && a[i][j] == a[i + 2][j - 2] &&
            a[i][j] == '0') {
          if (o < x) {
            cout << "illegal";
            return 0;
          }
          cout << "the second player won";
          return 0;
        }
        if (a[i][j] == 'X') x1++;
        if (a[i][j] == '0') o1++;
        if (a[i][j] == '.') d1++;
      }
      d2 = d1 + d2;
      d1 = 0;
      o2 = o1 + o2;
      o1 = 0;
      x2 = x1 + x2;
      x1 = 0;
    }
    if (d2 == 0) {
      cout << "draw";
      return 0;
    }
    if (x2 == o2) {
      cout << "first";
      return 0;
    }
    if (x2 > o2) {
      cout << "second";
      return 0;
    }
  }
}
