#include <bits/stdc++.h>
int judge(char x[5][5]) {
  int i, j, flag1 = 0, flag2 = 0;
  for (i = 0; i < 3; i++)
    if (x[i][0] == x[i][1] && x[i][1] == x[i][2]) {
      if (x[i][0] == 'X')
        flag1 = 1;
      else if (x[i][0] == '0')
        flag2 = 1;
    }
  for (i = 0; i < 3; i++)
    if (x[0][i] == x[1][i] && x[1][i] == x[2][i]) {
      if (x[0][i] == 'X')
        flag1 = 1;
      else if (x[0][i] == '0')
        flag2 = 1;
    }
  if ((x[0][0] == x[1][1] && x[1][1] == x[2][2]) ||
      (x[0][2] == x[1][1] && x[1][1] == x[2][0])) {
    if (x[1][1] == 'X')
      flag1 = 1;
    else if (x[1][1] == '0')
      flag2 = 1;
  }
  if (flag1 && flag2)
    return -1;
  else {
    if (!flag1 && !flag2)
      return 0;
    else if (flag1 && !flag2)
      return 1;
  }
  return 2;
}
int main() {
  char gri[5][5];
  int i, j, num1, num2, flag;
  while (scanf("%s", gri[0]) != EOF) {
    scanf("%s", gri[1]);
    scanf("%s", gri[2]);
    num1 = 0;
    num2 = 0;
    for (i = 0; i < 3; i++)
      for (j = 0; j < 3; j++) {
        if (gri[i][j] == 'X') num1++;
        if (gri[i][j] == '0') num2++;
      }
    flag = judge(gri);
    if (num2 > num1 || num1 - num2 > 1 || flag == -1 ||
        (num1 - num2 == 1 && flag == 2) || (num1 - num2 == 0 && flag == 1))
      printf("illegal\n");
    else {
      if (flag == 1)
        printf("the first player won\n");
      else {
        if (flag == 2)
          printf("the second player won\n");
        else {
          if (num1 + num2 == 9)
            printf("draw\n");
          else {
            if (num1 > num2)
              printf("second\n");
            else
              printf("first\n");
          }
        }
      }
    }
  }
  return 0;
}
