#include <bits/stdc++.h>
using namespace std;
int main() {
  char arr[4][4];
  int i, j, countx = 0, countz = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == 'X') {
        countx++;
      } else if (arr[i][j] == '0')
        countz++;
    }
  }
  int xv = 0, xo = 0;
  for (int i = 0; i < 3; i++) {
    int cx = 0, co = 0;
    for (int j = 0; j < 3; j++) {
      if (arr[j][i] == 'X') {
        cx++;
      } else if (arr[j][i] == '0') {
        co++;
      }
    }
    if (cx == 3) xv++;
    if (co == 3) xo++;
  }
  int yh = 0, yo = 0;
  for (int i = 0; i < 3; i++) {
    int cx = 0, co = 0;
    for (int j = 0; j < 3; j++) {
      if (arr[i][j] == 'X') {
        cx++;
      }
      if (arr[i][j] == '0') {
        co++;
      }
    }
    if (cx == 3) yh++;
    if (co == 3) yo++;
  }
  int dnrx = 0, dnro = 0, dnlx = 0, dnlo = 0;
  if (arr[0][0] == 'X' && arr[1][1] == 'X' && arr[2][2] == 'X') dnrx = 1;
  if (arr[0][0] == '0' && arr[1][1] == '0' && arr[2][2] == '0') dnro = 1;
  if (arr[2][0] == 'X' && arr[1][1] == 'X' && arr[0][2] == 'X') dnlx = 1;
  if (arr[2][0] == '0' && arr[1][1] == '0' && arr[0][2] == '0') dnlo = 1;
  if (countz > countx || (countx - countz > 1))
    cout << "illegal" << endl;
  else if (xv > 1 || xo > 1 || yh > 1 || yo > 1)
    cout << "illegal" << endl;
  else {
    if (xv == 1 || yh == 1 || dnrx == 1 || dnlx == 1) {
      if (countx - countz == 1) {
        cout << "the first player won" << endl;
      } else
        cout << "illegal" << endl;
    } else if (xo == 1 || yo == 1 || dnro == 1 || dnlo == 1) {
      if (countx == countz) {
        cout << "the second player won" << endl;
      } else
        cout << "illegal" << endl;
    } else if (countx + countz == 9) {
      cout << "draw" << endl;
    } else if (countx == countz) {
      cout << "first" << endl;
    } else if (countx == countz + 1) {
      cout << "second" << endl;
    }
  }
}
