#include <bits/stdc++.h>
using namespace std;
string a[3];
bool w(char c) {
  for (int i = 0; i < 3; i++) {
    if (a[i][0] == c && a[i][1] == c && a[i][2] == c) return true;
    if (a[0][i] == c && a[1][i] == c && a[2][i] == c) return true;
  }
  if (a[0][0] == c && a[1][1] == c && a[2][2] == c) return true;
  if (a[0][2] == c && a[1][1] == c && a[2][0] == c) return true;
  return false;
}
int main() {
  int cntx = 0, cnt0 = 0;
  for (int i = 0; i < 3; i++) cin >> a[i];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (a[i][j] == 'X') cntx++;
      if (a[i][j] == '0') cnt0++;
    }
  }
  if (!(cntx == cnt0 || cntx == cnt0 + 1)) {
    cout << "illegal";
    exit(0);
  }
  if (w('X') && cntx == cnt0) {
    cout << "illegal";
    exit(0);
  }
  if (w('0') && cntx > cnt0) {
    cout << "illegal";
    exit(0);
  }
  if (w('X') && w('0')) {
    cout << "illegal";
    exit(0);
  }
  if (w('X')) {
    cout << "the first player won";
    exit(0);
  }
  if (w('0')) {
    cout << "the second player won";
    exit(0);
  }
  if (cntx + cnt0 == 9) {
    cout << "draw";
    exit(0);
  }
  if (cntx == cnt0) {
    cout << "first";
    exit(0);
  } else {
    cout << "second";
    exit(0);
  }
  return 0;
}
