#include <bits/stdc++.h>
using namespace std;
char a[3][3];
char s[6][30] = {"first",
                 "second",
                 "illegal",
                 "the first player won",
                 "the second player won",
                 "draw"};
bool fx = false, fo = false;
void check() {
  fx = fo = false;
  for (int i = (0); i < (3); i++)
    if (a[0][i] != '.') {
      int cnt = 1 + (a[1][i] == a[0][i]) + (a[2][i] == a[0][i]);
      if (cnt == 3) a[0][i] == 'X' ? fx = true : fo = true;
    }
  for (int i = (0); i < (3); i++)
    if (a[i][0] != '.') {
      int cnt = 1 + (a[i][1] == a[i][0]) + (a[i][2] == a[i][0]);
      if (cnt == 3) a[i][0] == 'X' ? fx = true : fo = true;
    }
  if (a[0][0] != '.' && a[0][0] == a[1][1] && a[0][0] == a[2][2])
    a[0][0] == 'X' ? fx = true : fo = true;
  if (a[0][2] != '.' && a[0][2] == a[1][1] && a[0][2] == a[2][0])
    a[0][2] == 'X' ? fx = true : fo = true;
}
int main() {
  int num_x = 0, num_0 = 0;
  while (1) {
    num_x = 0, num_0 = 0;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (scanf("%c", &a[i][j]) == EOF) {
          return 0;
        }
        if (a[i][j] == '\n') {
          if (scanf("%c", &a[i][j]) == EOF) {
            return 0;
          }
        }
        if (a[i][j] == 'X') num_x++;
        if (a[i][j] == '0') num_0++;
      }
    }
    check();
    if (abs(num_x - num_0) > 1 || (fx && fo) || num_0 > num_x ||
        (fo && num_0 != num_x) || (fx && num_x - 1 != num_0)) {
      cout << s[2] << endl;
      continue;
    }
    if (fx) {
      cout << s[3] << endl;
      continue;
    }
    if (fo) {
      cout << s[4] << endl;
      continue;
    }
    if (num_x + num_0 == 9) {
      cout << s[5] << endl;
      continue;
    }
    if (num_x == num_0) {
      cout << s[0] << endl;
      continue;
    }
    if (num_x > num_0) {
      cout << s[1] << endl;
      continue;
    }
  }
  return 0;
}
