#include <bits/stdc++.h>
using namespace std;
int s[4][4], who;
void win() {
  int i, j;
  who = 0;
  if (s[0][0] != 0 && s[0][0] == s[1][0] && s[0][0] == s[2][0])
    who |= (1 << s[0][0]);
  if (s[0][1] != 0 && s[0][1] == s[1][1] && s[0][1] == s[2][1])
    who |= (1 << s[0][1]);
  if (s[0][2] != 0 && s[0][2] == s[1][2] && s[0][2] == s[2][2])
    who |= (1 << s[0][2]);
  if (s[0][0] != 0 && s[0][0] == s[0][1] && s[0][0] == s[0][2])
    who |= (1 << s[0][0]);
  if (s[1][0] != 0 && s[1][0] == s[1][1] && s[1][0] == s[1][2])
    who |= (1 << s[1][0]);
  if (s[2][0] != 0 && s[2][0] == s[2][1] && s[2][0] == s[2][2])
    who |= (1 << s[2][0]);
  if (s[0][0] != 0 && s[0][0] == s[1][1] && s[0][0] == s[2][2])
    who |= (1 << s[0][0]);
  if (s[0][2] != 0 && s[0][2] == s[1][1] && s[0][2] == s[2][0])
    who |= (1 << s[0][2]);
}
int main() {
  int i, j, fir = 0, sec = 0, emp = 0;
  char ch;
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      scanf(" %c", &ch);
      if (ch == 'X')
        s[i][j] = 1, fir++;
      else if (ch == '0')
        s[i][j] = 2, sec++;
      else
        s[i][j] = 0, emp++;
    }
  }
  if ((fir == sec + 1) || (fir == sec)) {
    win();
    if (who == 0) {
      if (emp == 0)
        printf("draw\n");
      else if (fir == sec + 1)
        printf("second\n");
      else
        printf("first\n");
    } else {
      if (who == 2 && fir == sec + 1)
        printf("the first player won\n");
      else if (who == 4 && fir == sec)
        printf("the second player won\n");
      else
        printf("illegal\n");
    }
  } else {
    printf("illegal\n");
  }
  return 0;
}
