#include <bits/stdc++.h>
using namespace std;
int count_symbol(const vector<string>& Board, char c) {
  int result = 0;
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (Board[i][j] == c) {
        ++result;
      }
    }
  }
  return result;
}
bool all_is_symbol(char c1, char c2, char c3, char c) {
  if ((c1 == c) && (c2 == c) && (c3 == c)) {
    return true;
  } else {
    return false;
  }
}
bool first_player_won(const vector<string>& Board) {
  if (all_is_symbol(Board[0][0], Board[0][1], Board[0][2], 'X') ||
      all_is_symbol(Board[1][0], Board[1][1], Board[1][2], 'X') ||
      all_is_symbol(Board[2][0], Board[2][1], Board[2][2], 'X') ||
      all_is_symbol(Board[0][0], Board[1][0], Board[2][0], 'X') ||
      all_is_symbol(Board[0][1], Board[1][1], Board[2][1], 'X') ||
      all_is_symbol(Board[0][2], Board[1][2], Board[2][2], 'X') ||
      all_is_symbol(Board[0][0], Board[1][1], Board[2][2], 'X') ||
      all_is_symbol(Board[0][2], Board[1][1], Board[2][0], 'X')) {
    return true;
  }
  return false;
}
bool second_player_won(const vector<string>& Board) {
  if (all_is_symbol(Board[0][0], Board[0][1], Board[0][2], '0') ||
      all_is_symbol(Board[1][0], Board[1][1], Board[1][2], '0') ||
      all_is_symbol(Board[2][0], Board[2][1], Board[2][2], '0') ||
      all_is_symbol(Board[0][0], Board[1][0], Board[2][0], '0') ||
      all_is_symbol(Board[0][1], Board[1][1], Board[2][1], '0') ||
      all_is_symbol(Board[0][2], Board[1][2], Board[2][2], '0') ||
      all_is_symbol(Board[0][0], Board[1][1], Board[2][2], '0') ||
      all_is_symbol(Board[0][2], Board[1][1], Board[2][0], '0')) {
    return true;
  }
  return false;
}
bool illegal(const vector<string>& Board) {
  if (first_player_won(Board) && second_player_won(Board)) {
    return true;
  }
  if (first_player_won(Board) &&
      !(count_symbol(Board, 'X') == count_symbol(Board, '0') + 1)) {
    return true;
  }
  if ((second_player_won(Board) &&
       !(count_symbol(Board, 'X') == count_symbol(Board, '0')))) {
    return true;
  }
  int q_X = count_symbol(Board, 'X');
  int q_0 = count_symbol(Board, '0');
  if ((q_X == q_0) || (q_X == q_0 + 1)) {
    return false;
  } else {
    return true;
  }
}
int main(int argc, char** argv) {
  vector<string> Board;
  for (int i = 0; i < 3; ++i) {
    string temp;
    cin >> temp;
    Board.push_back(temp);
  }
  if (illegal(Board)) {
    cout << "illegal" << endl;
  } else if (first_player_won(Board)) {
    cout << "the first player won" << endl;
  } else if (second_player_won(Board)) {
    cout << "the second player won" << endl;
  } else if (count_symbol(Board, '.') == 0) {
    cout << "draw" << endl;
  } else if (count_symbol(Board, 'X') == count_symbol(Board, '0')) {
    cout << "first" << endl;
  } else if (count_symbol(Board, 'X') == count_symbol(Board, '0') + 1) {
    cout << "second" << endl;
  }
  return 0;
}
