#include <bits/stdc++.h>
int main() {
  char s[9];
  int f = 0, d, i, count_x = 0, count_z = 0, first = 0, second = 0;
  scanf("%c%c%c\n", &s[0], &s[1], &s[2]);
  scanf("%c%c%c\n", &s[3], &s[4], &s[5]);
  scanf("%c%c%c", &s[6], &s[7], &s[8]);
  for (i = 0; i < 9; i++) {
    if (s[i] == 'X') {
      count_x++;
    }
    if (s[i] == '0') {
      count_z++;
    }
  }
  d = count_x - count_z;
  if (count_x == 0 && count_z == 0) {
    printf("first");
    goto end;
  }
  if (d > 1 || d < 0) {
    printf("illegal");
    goto end;
  }
  if ((s[0] == 'X' && s[1] == 'X' && s[2] == 'X') ||
      (s[3] == 'X' && s[4] == 'X' && s[5] == 'X') ||
      (s[6] == 'X' && s[7] == 'X' && s[8] == 'X') ||
      (s[0] == 'X' && s[3] == 'X' && s[6] == 'X') ||
      (s[1] == 'X' && s[4] == 'X' && s[7] == 'X') ||
      (s[2] == 'X' && s[5] == 'X' && s[8] == 'X') ||
      (s[0] == 'X' && s[4] == 'X' && s[8] == 'X') ||
      (s[2] == 'X' && s[4] == 'X' && s[6] == 'X')) {
    first++;
  }
  if ((s[0] == '0' && s[1] == '0' && s[2] == '0') ||
      (s[3] == '0' && s[4] == '0' && s[5] == '0') ||
      (s[6] == '0' && s[7] == '0' && s[8] == '0') ||
      (s[0] == '0' && s[3] == '0' && s[6] == '0') ||
      (s[1] == '0' && s[4] == '0' && s[7] == '0') ||
      (s[2] == '0' && s[5] == '0' && s[8] == '0') ||
      (s[0] == '0' && s[4] == '0' && s[8] == '0') ||
      (s[2] == '0' && s[4] == '0' && s[6] == '0')) {
    second++;
  }
  if (first == 1 && second == 0) {
    if (count_x != count_z + 1) {
      printf("illegal");
      goto end;
    }
  }
  if (first == 0 && second == 1) {
    if (count_x != count_z) {
      printf("illegal");
      goto end;
    }
  }
  if (first == 1 && second == 0) {
    printf("the first player won");
    goto end;
  }
  if (first == 0 && second == 1) {
    printf("the second player won");
    goto end;
  }
  if (first == 1 && second == 1) {
    printf("illegal");
    goto end;
  }
  if (count_x + count_z == 9) {
    printf("draw");
    goto end;
  }
  if (count_x > count_z) {
    printf("second");
    goto end;
  }
  if (count_x <= count_z) {
    printf("first");
  }
end:;
  return 0;
}
