#include <bits/stdc++.h>
using namespace std;
int main() {
  char ar[3][3];
  unsigned int oNum = 0, xNum = 0, dotNum = 0;
  for (unsigned int i = 0; i < 3; i++) {
    for (unsigned int j = 0; j < 3; j++) {
      cin >> ar[i][j];
      if (ar[i][j] == 'X')
        xNum++;
      else if (ar[i][j] == '0')
        oNum++;
      else
        dotNum++;
    }
  }
  bool stateP1 = false, stateP2 = false;
  for (unsigned int i = 0; i < 3; i++) {
    unsigned int countVert = 0, countColum = 0;
    for (unsigned int j = 0; j < 2; j++) {
      if (ar[j][i] == ar[j + 1][i]) countVert++;
      if (ar[i][j] == ar[i][j + 1]) countColum++;
    }
    if ((countColum == 2 && ar[i][0] == 'X') ||
        (countVert == 2 && ar[0][i] == 'X'))
      stateP1 = true;
    if ((countColum == 2 && ar[i][0] == '0') ||
        (countVert == 2 && ar[0][i] == '0'))
      stateP2 = true;
  }
  if (ar[0][0] == ar[1][1] && ar[0][0] == ar[2][2] && ar[0][0] == 'X')
    stateP1 = true;
  if (ar[0][0] == ar[1][1] && ar[0][0] == ar[2][2] && ar[0][0] == '0')
    stateP2 = true;
  if (ar[0][2] == ar[1][1] && ar[0][2] == ar[2][0] && ar[0][2] == 'X')
    stateP1 = true;
  if (ar[0][2] == ar[1][1] && ar[0][2] == ar[2][0] && ar[0][2] == '0')
    stateP2 = true;
  if ((stateP1 && stateP2) || (stateP1 && (xNum != oNum + 1)) ||
      (stateP2 && oNum != xNum) || (xNum != oNum && xNum != oNum + 1))
    cout << "illegal" << endl;
  else if (stateP1)
    cout << "the first player won" << endl;
  else if (stateP2)
    cout << "the second player won" << endl;
  else if (xNum == oNum && dotNum != 0)
    cout << "first" << endl;
  else if (xNum == oNum + 1 && dotNum != 0)
    cout << "second" << endl;
  else
    cout << "draw" << endl;
  return 0;
}
