#include <bits/stdc++.h>
using namespace std;
template <class AC>
void r(AC &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    f |= (ch == '-');
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x = f ? -x : x;
  return;
}
string s[5];
vector<int> v;
int work(char c) {
  int sum = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      sum += s[i][j] == c;
    }
  }
  return sum;
}
int tot(char c) {
  int sum = 0, nb = 0, tt = (1 << 9) - 1;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (s[i][j] == c) sum |= (1 << (i * 3 + j));
    }
  }
  for (int i = 0; i < v.size(); i++) {
    if ((sum & v[i]) == v[i]) {
      nb++;
      tt &= v[i];
    }
  }
  if (nb == 0) return nb;
  if (tt == 0) return 2;
  return 1;
}
int main() {
  cin >> s[0];
  cin >> s[1];
  cin >> s[2];
  for (int i = 0; i < 3; i++)
    v.push_back((1 << i * 3) + (1 << i * 3 + 1) + (1 << i * 3 + 2));
  for (int i = 0; i < 3; i++)
    v.push_back((1 << i) + (1 << i + 3) + (1 << i + 6));
  v.push_back((1 << 0) + (1 << 4) + (1 << 8));
  v.push_back((1 << 2) + (1 << 4) + (1 << 6));
  int x = work('X'), y = work('0');
  if (x < y || x > y + 1) {
    puts("illegal");
    return 0;
  }
  int dx = tot('X'), dy = tot('0');
  if (dx == 2 || dy == 2 || (x == y && dx == 1) || (x != y && dy == 1)) {
    puts("illegal");
    return 0;
  }
  if (dx == 1) {
    puts("the first player won");
    return 0;
  }
  if (dy == 1) {
    puts("the second player won");
    return 0;
  }
  if (x + y == 9) {
    puts("draw");
    return 0;
  }
  if (x == y) {
    puts("first");
    return 0;
  } else {
    puts("second");
    return 0;
  }
  return 0;
}
