#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e5 + 5;
string s[3];
void ill() {
  cout << "illegal\n";
  exit(0);
}
bool win(char c) {
  for (int i = 0; i < 3; i++) {
    bool ok = true;
    for (int j = 0; j < 3; j++) {
      if (s[i][j] != c) ok = false;
    }
    if (ok) return true;
    ok = true;
    for (int j = 0; j < 3; j++) {
      if (s[j][i] != c) ok = false;
    }
    if (ok) return true;
  }
  if (s[0][0] == c && s[1][1] == c && s[2][2] == c) return true;
  if (s[0][2] == c && s[1][1] == c && s[2][0] == c) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  for (int i = 0; i < 3; i++) cin >> s[i];
  int cntx = 0, cnty = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (s[i][j] == 'X')
        cntx++;
      else if (s[i][j] == '0')
        cnty++;
    }
  }
  if (cntx > cnty + 1 || cnty > cntx) ill();
  bool xwon = win('X');
  bool ywon = win('0');
  if (xwon && ywon) ill();
  if (xwon && cntx == cnty) ill();
  if (ywon && cntx > cnty) ill();
  if (xwon)
    cout << "the first player won\n";
  else if (ywon)
    cout << "the second player won\n";
  else if (cntx + cnty == 9)
    cout << "draw\n";
  else if (cntx == cnty)
    cout << "first\n";
  else
    cout << "second\n";
}
