#include <bits/stdc++.h>
using namespace std;
char s[3][3];
int X, O, x, o;
inline void Won() {
  X = O = 0;
  int aRow, bRow, aCol, bCol;
  for (int i = 0; i < 3; i++) {
    aRow = bRow = aCol = bCol = 0;
    for (int j = 0; j < 3; j++) {
      if (s[i][j] == 'X') aRow++;
      if (s[j][i] == 'X') aCol++;
      if (s[i][j] == '0') bRow++;
      if (s[j][i] == '0') bCol++;
    }
    if (aRow == 3 || aCol == 3) X++;
    if (bRow == 3 || bCol == 3) O++;
  }
  if (s[0][0] == s[1][1] && s[1][1] == s[2][2] && s[2][2] == 'X') X++;
  if (s[0][2] == s[1][1] && s[1][1] == s[2][0] && s[2][0] == 'X') X++;
  if (s[0][0] == s[1][1] && s[1][1] == s[2][2] && s[2][2] == '0') O++;
  if (s[0][2] == s[1][1] && s[1][1] == s[2][0] && s[2][0] == '0') O++;
}
int main() {
  x = o = 0;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      cin >> s[i][j];
      if (s[i][j] == 'X')
        x++;
      else if (s[i][j] == '0')
        o++;
    }
  Won();
  if (X >= 1 && O == 0 && x - o == 1)
    cout << "the first player won" << endl;
  else if (X == 0 && O >= 1 && x == o)
    cout << "the second player won" << endl;
  else if (X == 0 && O == 0 && x + o == 9 && x - o == 1)
    cout << "draw" << endl;
  else if (X == 0 && O == 0 && x == o)
    cout << "first" << endl;
  else if (X == 0 && O == 0 && x == o + 1)
    cout << "second" << endl;
  else
    cout << "illegal" << endl;
  return 0;
}
