#include <bits/stdc++.h>
const int none = 1000;
int map[3][3];
int F = 0, S = 0;
bool Fwin = false, Swin = false;
void init() {
  for (int i = 0; i < 3; i++) {
    char s[5];
    scanf("%s", s);
    for (int j = 0; j < 3; j++)
      if (s[j] == 'X') {
        F++;
        map[i][j] = 1;
      } else if (s[j] == '0') {
        S++;
        map[i][j] = 2;
      } else
        map[i][j] = none;
  }
}
void doit() {
  for (int i = 0; i < 3; i++) {
    int cnt = 0;
    for (int j = 0; j < 3; j++) cnt += map[i][j];
    if (cnt == 3) Fwin = true;
    if (cnt == 6) Swin = true;
  }
  for (int j = 0; j < 3; j++) {
    int cnt = 0;
    for (int i = 0; i < 3; i++) cnt += map[i][j];
    if (cnt == 3) Fwin = true;
    if (cnt == 6) Swin = true;
  }
  int cnt = map[0][0] + map[1][1] + map[2][2];
  if (cnt == 3) Fwin = true;
  if (cnt == 6) Swin = true;
  cnt = map[2][0] + map[1][1] + map[0][2];
  if (cnt == 3) Fwin = true;
  if (cnt == 6) Swin = true;
  if ((Fwin && Swin) || F - S >= 2 || S - F >= 1 || (Fwin && S == F) ||
      (Swin && S != F))
    printf("illegal\n");
  else if (Fwin)
    printf("the first player won\n");
  else if (Swin)
    printf("the second player won\n");
  else if (S + F == 9)
    printf("draw\n");
  else if (S == F)
    printf("first\n");
  else
    printf("second\n");
}
int main() {
  init();
  doit();
  return 0;
}
