#include <bits/stdc++.h>
using namespace std;
int checkWin(char arr[3][3], char a) {
  for (int i = 0; i < 3; i++) {
    if (arr[i][0] == a && arr[i][1] == a && arr[i][2] == a) {
      return 1;
    }
  }
  for (int i = 0; i < 3; i++) {
    if (arr[0][i] == a && arr[1][i] == a && arr[2][i] == a) {
      return 1;
    }
  }
  if (arr[0][0] == a && arr[1][1] == a && arr[2][2] == a) {
    return 1;
  }
  if (arr[2][0] == a && arr[1][1] == a && arr[0][2] == a) {
    return 1;
  }
  return 0;
}
int main() {
  char arr[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> arr[i][j];
    }
  }
  int countX = 0, countO = 0, countDot = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (arr[i][j] == '0') {
        countO++;
      } else if (arr[i][j] == 'X') {
        countX++;
      } else {
        countDot++;
      }
    }
  }
  int r1 = checkWin(arr, 'X'), r2 = checkWin(arr, '0');
  if (countO > countX || abs(countX - countO) >= 2 ||
      (r1 == 1 && countO == countX) || (r2 == 1 && countO < countX)) {
    cout << "illegal";
    return 0;
  }
  if (r1) {
    cout << "the first player won";
    return 0;
  }
  if (r2) {
    cout << "the second player won";
    return 0;
  }
  if (countDot == 0) {
    cout << "draw";
    return 0;
  }
  if (countO < countX) {
    cout << "second";
  } else {
    cout << "first";
  }
}
