#include <bits/stdc++.h>
using namespace std;
int i, j, X, O, A[8][2];
char C[3][3];
bool XM, OM, ND;
int main() {
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      cin >> C[i][j];
      if (C[i][j] == 'X') {
        X++;
        A[i][0]++;
        A[j + 3][0]++;
        if (i == j) {
          A[6][0]++;
        }
        if (i + j == 2) {
          A[7][0]++;
        }
      } else if (C[i][j] == '0') {
        O++;
        A[i][1]++;
        A[j + 3][1]++;
        if (i == j) {
          A[6][1]++;
        }
        if (i + j == 2) {
          A[7][1]++;
        }
      }
    }
  }
  if (X != O && X != O + 1) {
    cout << "illegal\n";
    return 0;
  }
  for (i = 0; i < 8; i++) {
    if (A[i][0] == 3) {
      XM = 1;
    } else if (A[i][0] == 0) {
      ND = 1;
    }
    if (A[i][1] == 3) {
      OM = 1;
    } else if (A[i][1] == 0) {
      ND = 1;
    }
  }
  if (XM && OM) {
    cout << "illegal\n";
    return 0;
  }
  if (XM) {
    if (X == O) {
      cout << "illegal\n";
    } else {
      cout << "the first player won\n";
    }
    return 0;
  }
  if (OM) {
    if (X != O) {
      cout << "illegal\n";
    } else {
      cout << "the second player won\n";
    }
    return 0;
  }
  if (X + O == 9) {
    cout << "draw\n";
    return 0;
  }
  if (X == O) {
    cout << "first\n";
  } else {
    cout << "second\n";
  }
}
