#include <bits/stdc++.h>
using namespace std;
int isWon1(int a[3][3]) {
  int count = 0;
  if (a[0][0] == a[0][1] && a[0][0] == a[0][2] && a[0][0] == 1) count++;
  if (a[1][0] == a[1][1] && a[1][0] == a[1][2] && a[1][0] == 1) count++;
  if (a[2][0] == a[2][1] && a[2][0] == a[2][2] && a[2][0] == 1) count++;
  if (a[0][0] == a[1][0] && a[0][0] == a[2][0] && a[0][0] == 1) count++;
  if (a[0][1] == a[1][1] && a[0][1] == a[2][1] && a[0][1] == 1) count++;
  if (a[0][2] == a[1][2] && a[0][2] == a[2][2] && a[0][2] == 1) count++;
  if (a[0][0] == a[1][1] && a[0][0] == a[2][2] && a[0][0] == 1) count++;
  if (a[0][2] == a[1][1] && a[0][2] == a[2][0] && a[0][2] == 1) count++;
  return count;
}
int isWon2(int a[3][3]) {
  int count = 0;
  if (a[0][0] == a[0][1] && a[0][0] == a[0][2] && a[0][0] == 2) count++;
  if (a[1][0] == a[1][1] && a[1][0] == a[1][2] && a[1][0] == 2) count++;
  if (a[2][0] == a[2][1] && a[2][0] == a[2][2] && a[2][0] == 2) count++;
  if (a[0][0] == a[1][0] && a[0][0] == a[2][0] && a[0][0] == 2) count++;
  if (a[0][1] == a[1][1] && a[0][1] == a[2][1] && a[0][1] == 2) count++;
  if (a[0][2] == a[1][2] && a[0][2] == a[2][2] && a[0][2] == 2) count++;
  if (a[0][0] == a[1][1] && a[0][0] == a[2][2] && a[0][0] == 2) count++;
  if (a[0][2] == a[1][1] && a[0][2] == a[2][0] && a[0][2] == 2) count++;
  return count;
}
int main() {
  char c;
  int i, j, a[3][3], cx = 0, cy = 0, c0 = 0;
  for (i = 0; i < 3; i++) {
    c = getchar();
    for (j = 0; j < 3; j++) {
      if (c == 'X') {
        a[i][j] = 1;
        cx++;
      } else if (c == '.') {
        a[i][j] = 0;
        c0++;
      } else if (c == '0') {
        a[i][j] = 2;
        cy++;
      }
      c = getchar();
    }
    while (c != '\n') c = getchar();
  }
  if (cx - cy > 1) {
    cout << "illegal" << endl;
    return 0;
  }
  if (cx - cy < 0) {
    cout << "illegal" << endl;
    return 0;
  }
  if (cx - cy == 1) {
    if (isWon1(a) == 1 && isWon2(a) == 0) {
      cout << "the first player won" << endl;
    } else if (cx == 5 && cy == 4 && isWon1(a) == 2) {
      cout << "the first player won" << endl;
    } else if (isWon1(a) == 0 && isWon2(a) == 0) {
      if (c0 == 0) {
        cout << "draw" << endl;
      } else
        cout << "second" << endl;
    } else
      cout << "illegal" << endl;
    return 0;
  }
  if (cx == cy) {
    if (isWon1(a) == 0 && isWon2(a) == 1) {
      cout << "the second player won" << endl;
    } else if (isWon1(a) == 0 && isWon2(a) == 0) {
      cout << "first" << endl;
    } else
      cout << "illegal" << endl;
    return 0;
  }
  return 0;
}
