#include <bits/stdc++.h>
int main(void) {
  char matrix[3][4];
  int ft = 0, st = 0;
  int fw = 0, sw = 0;
  for (int i = 0; i < 3; i++) {
    scanf("%s", &matrix[i]);
    for (int j = 0; j < 3; j++) {
      if (matrix[i][j] == 'X')
        ft++;
      else if (matrix[i][j] == '0')
        st++;
    }
    if (matrix[i][0] == matrix[i][1] && matrix[i][1] == matrix[i][2]) {
      if (matrix[i][0] == 'X')
        fw++;
      else if (matrix[i][0] != '.')
        sw++;
    }
  }
  for (int i = 0; i < 3; i++) {
    if (matrix[0][i] == matrix[1][i] && matrix[1][i] == matrix[2][i]) {
      if (matrix[0][i] == 'X')
        fw++;
      else if (matrix[0][i] != '.')
        sw++;
    }
  }
  if (matrix[0][0] == matrix[1][1] && matrix[1][1] == matrix[2][2]) {
    if (matrix[0][0] == 'X')
      fw++;
    else if (matrix[0][0] != '.')
      sw++;
  }
  if (matrix[0][2] == matrix[1][1] && matrix[1][1] == matrix[2][0]) {
    if (matrix[0][2] == 'X')
      fw++;
    else if (matrix[0][2] != '.')
      sw++;
  }
  if (ft - st > 1 || (fw > 0 && sw > 0) || st - ft > 0 ||
      (fw > 0 && ft - st != 1) || (sw > 0 && ft - st != 0))
    printf("illegal\n");
  else if (fw > 0) {
    printf("the first player won");
  } else if (sw > 0) {
    printf("the second player won");
  } else if (ft - st > 0 && ft + st != 9) {
    printf("second");
  } else if (ft + st == 9)
    printf("draw");
  else
    printf("first");
  return 0;
}
