#include <bits/stdc++.h>
using namespace std;
int Int() {
  int x;
  scanf("%d", &x);
  return x;
}
long long Long() {
  long long x;
  scanf("%lld", &x);
  return x;
}
double Double() {
  double x;
  scanf("%lf", &x);
  return x;
}
const int N = (int)1e5 + 5;
const long long MOD = (int)1e9 + 7;
string s[4];
bool win(char c) {
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (s[i][j] == c) {
        if (i > 0 and j > 0 and i < 2 and j < 2)
          if (s[i - 1][j - 1] == c and s[i + 1][j + 1] == c) return true;
        if (i > 1 and j > 1)
          if (s[i - 1][j - 1] == c and s[i - 2][j - 2] == c) return true;
        if (i < 1 and j < 1)
          if (s[i + 1][j + 1] == c and s[i + 2][j + 2] == c) return true;
        if (i < 1 and j > 1)
          if (s[i + 1][j - 1] == c and s[i + 2][j - 2] == c) return true;
        if (i > 1 and j < 1)
          if (s[i - 1][j + 1] == c and s[i - 2][j + 2] == c) return true;
        if (i == 1 and j == 1)
          if (s[i + 1][j - 1] == c and s[i - 1][j + 1] == c) return true;
        if (j == 1)
          if (s[i][j + 1] == c and s[i][j - 1] == c) return true;
        if (j == 0)
          if (s[i][j + 1] == c and s[i][j + 2] == c) return true;
        if (j == 2)
          if (s[i][j - 1] == c and s[i][j - 2] == c) return true;
        if (i == 1)
          if (s[i - 1][j] == c and s[i + 1][j] == c) return true;
        if (i == 2)
          if (s[i - 1][j] == c and s[i - 2][j] == c) return true;
        if (i == 0)
          if (s[i + 1][j] == c and s[i + 2][j] == c) return true;
      }
    }
  }
  return false;
}
int main() {
  for (int i = 0; i < 3; i++) cin >> s[i];
  bool fwin = win('X');
  bool swin = win('0');
  int cross = 0, zero = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cross += (s[i][j] == 'X');
      zero += (s[i][j] == '0');
    }
  }
  if ((fwin and swin) or (cross > zero + 1) or (zero > cross) or
      (fwin and cross == zero) or (swin and cross > zero))
    return puts("illegal"), 0;
  if (fwin) return puts("the first player won"), 0;
  if (swin) return puts("the second player won"), 0;
  if (zero == cross and zero + cross < 9) return puts("first"), 0;
  if (zero < cross and zero + cross < 9) return puts("second"), 0;
  puts("draw");
  return 0;
}
