#include <bits/stdc++.h>
using namespace std;
struct D {
  int turn;
  char result;
};
map<string, D> f;
int Judge(const string& s) {
  for (int i = 0; i < 3; ++i) {
    if (s[i] != '.' && s[i] == s[i + 3] && s[i] == s[i + 6]) return s[i];
    if (s[3 * i] != '.' && s[3 * i] == s[3 * i + 1] && s[3 * i] == s[3 * i + 2])
      return s[3 * i];
  }
  if (s[0] != '.' && s[0] == s[4] && s[0] == s[8]) return s[0];
  if (s[2] != '.' && s[2] == s[4] && s[2] == s[6]) return s[2];
  if (s.find(".") == string::npos) return '.';
  return 0;
}
void Go(const string& s, int turn) {
  map<string, D>::iterator it = f.find(s);
  if (it != f.end()) return;
  D& r = f[s];
  r.turn = turn;
  r.result = Judge(s);
  if (r.result) return;
  string s2 = s;
  for (int i = 0; i < 9; ++i)
    if (s[i] == '.') {
      s2[i] = turn == 1 ? 'X' : '0';
      Go(s2, 3 - turn);
      s2[i] = '.';
    }
}
int main() {
  Go(string(9, '.'), 1);
  string s;
  for (int i = 0, k = 1; i < 3; ++i) {
    char buf[10];
    cin >> buf;
    s += buf;
  }
  if (!f.count(s)) {
    cout << "illegal" << endl;
    return 0;
  }
  D& r = f[s];
  if (!r.result)
    cout << (r.turn == 1 ? "first" : "second") << endl;
  else
    cout << (r.result == '.'   ? "draw"
             : r.result == 'X' ? "the first player won"
                               : "the second player won")
         << endl;
  return 0;
}
