#include <bits/stdc++.h>
using namespace std;
int xcnt;
int ocnt;
char ma[3][3];
int win(char c) {
  for (int i = 0; i < 3; i++) {
    if (ma[i][0] == c && ma[i][1] == c && ma[i][2] == c) return 1;
    if (ma[0][i] == c && ma[1][i] == c && ma[2][i] == c) return 1;
  }
  if (ma[1][1] != c) return 0;
  if (ma[0][0] == c && ma[2][2] == c) return 1;
  if (ma[0][2] == c && ma[2][0] == c) return 1;
  return 0;
}
int legal() {
  if (xcnt - ocnt > 1) return 0;
  if (xcnt - ocnt < 0) return 0;
  if (win('X') && xcnt == ocnt) return 0;
  if (win('0') && xcnt - ocnt == 1) return 0;
  return 1;
}
int main() {
  xcnt = 0;
  ocnt = 0;
  for (int i = 0; i < 3; i++) {
    scanf("%s", ma[i]);
    for (int j = 0; j < 3; j++) {
      xcnt += (ma[i][j] == 'X');
      ocnt += (ma[i][j] == '0');
    }
  }
  if (!legal())
    printf("illegal\n");
  else if (win('X'))
    printf("the first player won\n");
  else if (win('0'))
    printf("the second player won\n");
  else if (xcnt + ocnt == 9)
    printf("draw\n");
  else if (xcnt == ocnt)
    printf("first\n");
  else if (xcnt - ocnt == 1)
    printf("second\n");
}
