#include <bits/stdc++.h>
using namespace std;
vector<string> pos;
string base;
bool check(void) {
  bool res = true;
  for (int i = 0; i < 9; ++i)
    if (base[i] != pos[pos.size() - 1][i]) res = false;
  return res;
};
bool won(void) {
  for (int i = 0; i < 3; ++i)
    if (pos[pos.size() - 1][i * 3] == 'X' &&
        pos[pos.size() - 1][i * 3 + 1] == 'X' &&
        pos[pos.size() - 1][i * 3 + 2] == 'X')
      return true;
  for (int i = 0; i < 3; ++i)
    if (pos[pos.size() - 1][i * 3] == '0' &&
        pos[pos.size() - 1][i * 3 + 1] == '0' &&
        pos[pos.size() - 1][i * 3 + 2] == '0')
      return true;
  for (int i = 0; i < 3; ++i)
    if (pos[pos.size() - 1][i] == 'X' && pos[pos.size() - 1][3 + i] == 'X' &&
        pos[pos.size() - 1][6 + i] == 'X')
      return true;
  for (int i = 0; i < 3; ++i)
    if (pos[pos.size() - 1][i] == '0' && pos[pos.size() - 1][3 + i] == '0' &&
        pos[pos.size() - 1][6 + i] == '0')
      return true;
  if (pos[pos.size() - 1][0] == 'X' && pos[pos.size() - 1][4] == 'X' &&
      pos[pos.size() - 1][8] == 'X')
    return true;
  if (pos[pos.size() - 1][2] == 'X' && pos[pos.size() - 1][4] == 'X' &&
      pos[pos.size() - 1][6] == 'X')
    return true;
  if (pos[pos.size() - 1][0] == '0' && pos[pos.size() - 1][4] == '0' &&
      pos[pos.size() - 1][8] == '0')
    return true;
  if (pos[pos.size() - 1][2] == '0' && pos[pos.size() - 1][4] == '0' &&
      pos[pos.size() - 1][6] == '0')
    return true;
  return false;
}
bool draw() {
  bool res = true;
  for (int i = 0; i < 9; ++i)
    if (pos[pos.size() - 1][i] == '.') res = false;
  return res;
}
void iter(int who) {
  if (check()) {
    if (won())
      if (who == 1)
        cout << "the second player won";
      else
        cout << "the first player won";
    else if (draw())
      cout << "draw";
    else if (who == 1)
      cout << "first";
    else
      cout << "second";
    throw(1);
  } else {
    if (won()) {
      pos.erase(pos.end() - 1);
      return;
    }
    if (who == 1) {
      for (int i = 0; i < 9; ++i)
        if (pos[pos.size() - 1][i] == '.' && base[i] == 'X') {
          pos.push_back(pos[pos.size() - 1]);
          pos[pos.size() - 1][i] = 'X';
          iter(!who);
        }
    } else {
      for (int i = 0; i < 9; ++i)
        if (pos[pos.size() - 1][i] == '.' && base[i] == '0') {
          pos.push_back(pos[pos.size() - 1]);
          pos[pos.size() - 1][i] = '0';
          iter(!who);
        }
    }
  }
  pos.erase(pos.end() - 1);
};
int main() {
  pos.push_back(".........");
  char c;
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j) {
      cin >> c;
      base += c;
    }
  try {
    iter(1);
    cout << "illegal";
  } catch (int) {
    return 0;
  }
  return 0;
}
