#include <bits/stdc++.h>
using namespace std;
char a[9];
int Q, M, W, Y, i;
int main() {
  for (i = 0; i < 9; i++) {
    cin >> a[i];
    if (a[i] == '0') W++;
    if (a[i] == 'X') Y++;
  }
  for (i = 0; i < 3; i++) {
    if (a[3 * i] == '0' && a[3 * i + 1] == '0' && a[3 * i + 2] == '0' ||
        a[i] == '0' && a[i + 3] == '0' && a[i + 6] == '0' ||
        a[0] == '0' && a[4] == '0' && a[8] == '0' ||
        a[2] == '0' && a[4] == '0' && a[6] == '0')
      Q = 1;
    if (a[3 * i] == 'X' && a[3 * i + 1] == 'X' && a[3 * i + 2] == 'X' ||
        a[i] == 'X' && a[i + 3] == 'X' && a[i + 6] == 'X' ||
        a[0] == 'X' && a[4] == 'X' && a[8] == 'X' ||
        a[2] == 'X' && a[4] == 'X' && a[6] == 'X')
      M = 1;
  }
  if ((M && Y != W + 1) || (Q && Y != W) || (Y != W + 1 && Y != W))
    cout << "illegal";
  else if (M)
    cout << "the first player won";
  else if (Q)
    cout << "the second player won";
  else if (Y + W == 9)
    cout << "draw";
  else if (Y == W)
    cout << "first";
  else
    cout << "second";
}
