#include <bits/stdc++.h>
int main() {
  char c[3][3];
  int x = 0, o = 0, W1 = 0, W2 = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      scanf("%c", &c[i][j]);
      if (c[i][j] == 'X') x++;
      if (c[i][j] == '0') o++;
    }
    char r;
    scanf("%c", &r);
  }
  if (!(x == o || x == o + 1)) {
    printf("illegal");
    return 0;
  }
  for (int i = 0; i < 3; i++) {
    if (c[i][0] == c[i][1] && c[i][0] == c[i][2]) {
      if (c[i][0] == 'X') W1 = 1;
      if (c[i][0] == '0') W2 = 1;
    }
    if (c[0][i] == c[1][i] && c[0][i] == c[2][i]) {
      if (c[0][i] == 'X') W1 = 1;
      if (c[0][i] == '0') W2 = 1;
    }
  }
  if (c[0][0] == c[1][1] && c[0][0] == c[2][2]) {
    if (c[0][0] == 'X') W1 = 1;
    if (c[0][0] == '0') W2 = 1;
  }
  if (c[0][2] == c[1][1] && c[0][2] == c[2][0]) {
    if (c[0][2] == 'X') W1 = 1;
    if (c[0][2] == '0') W2 = 1;
  }
  if (W1 == 1 && W2 == 1) {
    printf("illegal");
    return 0;
  }
  if (x > o && W2) {
    printf("illegal");
    return 0;
  }
  if (x == o && W1) {
    printf("illegal");
    return 0;
  }
  if (W1) {
    printf("the first player won");
    return 0;
  }
  if (W2) {
    printf("the second player won");
    return 0;
  }
  if (o + x == 9) {
    printf("draw");
    return 0;
  }
  if (x == o) {
    printf("first");
    return 0;
  }
  if (x > o) {
    printf("second");
    return 0;
  }
}
