#include <bits/stdc++.h>
using namespace std;
ifstream fin("1.in");
char ch[4][4];
long l1 = 0, l2 = 0;
int main(int argc, char** argv) {
  for (long i = 1; i <= 3; i++) {
    for (long j = 1; j <= 3; j++) {
      ch[i][j] = cin.get();
      if (ch[i][j] == 'X') l1++;
      if (ch[i][j] == '0') l2++;
    }
    cin.get();
  }
  if (l1 != l2 && l2 + 1 != l1) {
    cout << "illegal" << endl;
    return 0;
  }
  char c = '#';
  for (long i = 1; i <= 3; i++) {
    if (ch[i][1] != '.' && ch[i][1] == ch[i][3] && ch[i][2] == ch[i][3]) {
      if (c != '#' && c != ch[i][1]) {
        cout << "illegal" << endl;
        return 0;
      }
      c = ch[i][1];
    }
    if (ch[1][i] != '.' && ch[1][i] == ch[3][i] && ch[2][i] == ch[3][i]) {
      if (c != '#' && c != ch[1][i]) {
        cout << "illegal" << endl;
        return 0;
      }
      c = ch[1][i];
    }
  }
  if (ch[1][1] != '.' && ch[1][1] == ch[2][2] && ch[2][2] == ch[3][3]) {
    if (c != '#' && c != ch[1][1]) {
      cout << "illegal" << endl;
      return 0;
    }
    c = ch[1][1];
  }
  if (ch[1][3] != '.' && ch[1][3] == ch[2][2] && ch[2][2] == ch[3][1]) {
    if (c != '#' && c != ch[1][3]) {
      cout << "illegal" << endl;
      return 0;
    }
    c = ch[1][3];
  }
  if (c != '#') {
    if (c == 'X')
      if (l2 + 1 != l1)
        cout << "illegal" << endl;
      else
        cout << "the first player won" << endl;
    else if (l1 != l2)
      cout << "illegal" << endl;
    else
      cout << "the second player won" << endl;
    return 0;
  }
  if (l1 + l2 == 9) {
    cout << "draw" << endl;
    return 0;
  }
  if (l1 <= l2) {
    cout << "first" << endl;
    return 0;
  }
  if (l1 > l2) {
    cout << "second" << endl;
    return 0;
  }
  return 0;
}
