#include <bits/stdc++.h>
using namespace std;
char s[3][4];
int c1 = 0;
int c2 = 0;
bool fs = 0;
bool sn = 0;
void bad() {
  printf("illegal");
  exit(0);
}
int main() {
  for (int i = 0; i < 3; i++) {
    scanf("%s\n", s[i]);
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (s[i][j] == 'X')
        c1++;
      else if (s[i][j] == '0')
        c2++;
    }
  }
  int curr1 = 0;
  int curr2 = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i][0] == s[i][1] && s[i][1] == s[i][2] && s[i][2] != '.') {
      if (s[i][0] == 'X')
        curr1++;
      else
        curr2++;
    }
    if (curr1 > 1 || curr2 > 1) bad();
    fs = curr1;
    sn = curr2;
  }
  curr1 = 0;
  curr2 = 0;
  for (int i = 0; i < 3; i++) {
    curr1 = 0;
    curr2 = 0;
    if (s[0][i] == s[1][i] && s[1][i] == s[2][i] && s[2][i] != '.') {
      if (s[0][i] == 'X')
        curr1++;
      else
        curr2++;
    }
    if (curr1 > 1 || curr2 > 1) bad();
    fs |= curr1;
    sn |= curr2;
  }
  if (s[0][0] == s[1][1] && s[1][1] == s[2][2] && s[1][1] == 'X') fs = 1;
  if (s[0][0] == s[1][1] && s[1][1] == s[2][2] && s[1][1] == '0') sn = 1;
  if (s[0][2] == s[1][1] && s[1][1] == s[2][0] && s[0][2] == 'X') fs = 1;
  if (s[0][2] == s[1][1] && s[1][1] == s[2][0] && s[0][2] == '0') sn = 1;
  if (fs + sn > 1) bad();
  if (fs + sn == 0) {
    if (c1 == c2) {
      printf("first");
    } else if (c1 - 1 == c2) {
      if (c1 + c2 != 9)
        printf("second");
      else
        printf("draw");
    } else {
      bad();
    }
  } else {
    if (fs && c1 - 1 == c2) {
      printf("the first player won");
    } else if (sn && c1 == c2) {
      printf("the second player won");
    } else {
      bad();
    }
  }
  return 0;
}
