#include <bits/stdc++.h>
using namespace std;
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
using namespace std;
char grid[3][3];
int x, o;
bool won(char a) {
  for (int i = 0; i < 3; i++)
    if ((grid[i][0] == a && grid[i][1] == a && grid[i][2] == a) ||
        (grid[0][i] == a && grid[1][i] == a && grid[2][i] == a))
      return 1;
  if (grid[0][0] == a && grid[1][1] == a && grid[2][2] == a) return 1;
  if (grid[0][2] == a && grid[1][1] == a && grid[2][0] == a) return 1;
  return 0;
}
int main() {
  gets(grid[0]);
  gets(grid[1]);
  gets(grid[2]);
  bool dot = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (grid[i][j] == 'X')
        x++;
      else {
        if (grid[i][j] == '0')
          o++;
        else
          dot = 1;
      }
    }
  }
  int d = x - o;
  if (d != 0 && d != 1) {
    printf("illegal");
    return 0;
  }
  if (won('X') && won('0')) {
    printf("illegal");
    return 0;
  }
  if (won('X')) {
    if (d != 1)
      printf("illegal");
    else
      printf("the first player won");
    return 0;
  }
  if (won('0')) {
    if (d != 0)
      printf("illegal");
    else
      printf("the second player won");
    return 0;
  }
  if (!dot) {
    printf("draw");
    return 0;
  }
  if (d == 1)
    printf("second");
  else
    printf("first");
}
