#include <bits/stdc++.h>
using namespace std;
const long long INF = LONG_LONG_MAX;
long long MOD = 1000000009;
template <class T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  for (unsigned long long i = 0; i < v.size(); ++i)
    out << v[i] << (i < v.size() - 1 ? " " : "");
  return out;
}
template <class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &v) {
  out << "(" << v.first << ", " << v.second << ")";
  return out;
}
vector<complex<long long> > dirs = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
bool bound(complex<long long> p, long long r, long long c) {
  return p.real() >= 0 && p.real() < r && p.imag() >= 0 && p.imag() < c;
}
long long sign(long long x) { return (x > 0) - (x < 0); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  srand(time(NULL));
  long long board[3][3];
  char c;
  long long xs = 0, os = 0;
  for (long long i = (0); i < (long long)(3); ++i) {
    for (long long j = (0); j < (long long)(3); ++j) {
      cin >> c;
      if (c == 'X') {
        board[i][j] = 1;
        xs++;
      } else if (c == '0') {
        board[i][j] = -1;
        os++;
      } else if (c == '.')
        board[i][j] = 0;
      else
        cout << "WTF?! [input]" << endl;
    }
  }
  long long dxo = xs - os;
  long long turn = INF;
  if (dxo > 1 || dxo < 0)
    turn = 0;
  else if (dxo == 0)
    turn = 1;
  else if (dxo == 1)
    turn = -1;
  else
    cout << "WTF?! [turn]" << endl;
  vector<bool> won(3, false);
  long long hor, ver;
  for (long long i = (0); i < (long long)(3); ++i) {
    hor = board[i][0] + board[i][1] + board[i][2];
    ver = board[0][i] + board[1][i] + board[2][i];
    if (hor == -3 || ver == -3) won[0] = true;
    if (hor == 3 || ver == 3) won[2] = true;
  }
  long long dig1, dig2;
  dig1 = board[0][0] + board[1][1] + board[2][2];
  dig2 = board[0][2] + board[1][1] + board[2][0];
  if (dig1 == -3 || dig2 == -3) won[0] = true;
  if (dig1 == 3 || dig2 == 3) won[2] = true;
  if (turn == 0 || (won[0] && won[2]) || (won[0] && turn == -1) ||
      (won[2] && turn == 1))
    cout << "illegal";
  else if (won[2])
    cout << "the first player won";
  else if (won[0])
    cout << "the second player won";
  else if (xs + os == 9)
    cout << "draw";
  else if (turn == 1)
    cout << "first";
  else if (turn == -1)
    cout << "second";
  else
    cout << "WTF?! [output]";
  cout << endl;
}
