#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[5][5];
  int sx = 0, s0 = 0, q = 0;
  int i, j, k, m, n;
  int flag = 0, ok1 = 0, ok2 = 0;
  for (i = 0; i < 3; i++) {
    cin >> a[i];
    for (j = 0; j < 3; j++) {
      if (a[i][j] == 'X') {
        q++;
        sx++;
      }
      if (a[i][j] == '0') {
        s0++;
        q++;
      }
      if (a[i][j] != 'X' && a[i][j] != '0' && a[i][j] != '.') {
        ok1 = 1;
        ok2 = 1;
      }
    }
  }
  if (sx - s0 > 1 || sx - s0 < 0) {
    ok1 = 1;
    ok2 = 1;
  }
  if (ok1 + ok2 == 0) {
    for (i = 0; i < 3; i++) {
      flag = 0;
      for (j = 1; j < 3; j++) {
        if (a[i][0] != a[i][j]) {
          flag = 1;
          break;
        }
      }
      if (!flag) {
        if (a[i][0] == 'X') {
          ok1 = 1;
        } else {
          if (a[i][0] == '0') {
            ok2 = 1;
          }
        }
      }
    }
  }
  if (ok1 + ok2 == 0) {
    for (i = 0; i < 3; i++) {
      flag = 0;
      for (j = 1; j < 3; j++) {
        if (a[0][i] != a[j][i]) {
          flag = 1;
          break;
        }
      }
      if (!flag) {
        if (a[0][i] == 'X') {
          ok1 = 1;
        } else {
          if (a[0][i] == '0') {
            ok2 = 1;
          }
        }
      }
    }
  }
  if (ok1 + ok2 == 0 && a[0][0] == a[1][1] && a[0][0] == a[2][2]) {
    if (a[1][1] == 'X') {
      ok1 = 1;
    } else {
      if (a[1][1] == '0') {
        ok2 = 1;
      }
    }
  } else {
    if (ok1 + ok2 == 0 && a[0][2] == a[1][1] && a[1][1] == a[2][0]) {
      if (a[1][1] == 'X') {
        ok1 = 1;
      } else {
        if (a[1][1] == '0') {
          ok2 = 1;
        }
      }
    }
  }
  if (ok1 + ok2 == 0) {
    if (q == 9) {
      cout << "draw" << endl;
    } else {
      if (sx > s0) {
        cout << "second" << endl;
      } else {
        cout << "first" << endl;
      }
    }
  } else if (ok1 + ok2 == 2) {
    cout << "illegal" << endl;
  } else if (ok1 && sx > s0) {
    cout << "the first player won" << endl;
    ;
  } else if (ok2 && sx == s0) {
    cout << "the second player won" << endl;
  } else {
    cout << "illegal" << endl;
  }
  return 0;
}
