#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e2 + 5;
long long Black, White, Map[MAXN][MAXN], WinBlack, WinWhite;
char Str[MAXN];
long long QP(long long B, long long K, long long Mod) {
  long long Ans = 1;
  for (; K; K >>= 1, B = B * B % Mod)
    if (K & 1) Ans = Ans * B % Mod;
  return Ans;
}
template <class T>
void Read(T &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 * 10 + (Ch ^ 48);
    Ch = getchar();
  }
  X = F ? -X : X;
}
long long GCD(long long X, long long Y) { return Y == 0 ? X : GCD(Y, X % Y); }
int main() {
  for (long long i = 1; i <= 3; i++) {
    scanf("%s", Str + 1);
    for (long long j = 1; j <= 3; j++) {
      if (Str[j] == 'X') {
        Black++;
        Map[i][j] = 1;
      }
      if (Str[j] == '0') {
        White++;
        Map[i][j] = 2;
      }
    }
  }
  if (Black > White + 1 || Black < White) {
    printf("illegal\n");
    return 0;
  }
  for (long long i = 1; i <= 3; i++)
    if (Map[i][1] == 1 && Map[i][2] == 1 && Map[i][3] == 1) WinBlack++;
  for (long long i = 1; i <= 3; i++)
    if (Map[1][i] == 1 && Map[2][i] == 1 && Map[3][i] == 1) WinBlack++;
  if (Map[1][1] == 1 && Map[2][2] == 1 && Map[3][3] == 1) WinBlack++;
  if (Map[1][3] == 1 && Map[2][2] == 1 && Map[3][1] == 1) WinBlack++;
  for (long long i = 1; i <= 3; i++)
    if (Map[i][1] == 2 && Map[i][2] == 2 && Map[i][3] == 2) WinWhite++;
  for (long long i = 1; i <= 3; i++)
    if (Map[1][i] == 2 && Map[2][i] == 2 && Map[3][i] == 2) WinWhite++;
  if (Map[1][1] == 2 && Map[2][2] == 2 && Map[3][3] == 2) WinWhite++;
  if (Map[1][3] == 2 && Map[2][2] == 2 && Map[3][1] == 2) WinWhite++;
  if (WinBlack && WinWhite) {
    printf("illegal\n");
    return 0;
  } else if (WinBlack && !WinWhite) {
    if (Black == White + 1)
      printf("the first player won\n");
    else
      printf("illegal\n");
  } else if (!WinBlack && WinWhite) {
    if (Black == White)
      printf("the second player won\n");
    else
      printf("illegal\n");
  } else {
    if (Black + White == 9) {
      printf("draw\n");
      return 0;
    }
    if (Black == White)
      printf("first\n");
    else
      printf("second\n");
  }
  return 0;
}
