#include <bits/stdc++.h>
using namespace std;
string m[70000];
string s, g = ".........";
int did(string tmp) {
  int num = 0;
  int j = 1;
  for (int i = 8; i >= 0; i--) {
    if (tmp[i] == 'X') num += j;
    if (tmp[i] == '0') num += j * 2;
    j *= 3;
  }
  return num;
}
bool pan(string t, char p) {
  for (int i = 0; i < 3; i++)
    if (g[i * 3] == p && g[i * 3 + 1] == p && g[i * 3 + 2] == p) return true;
  for (int i = 0; i < 3; i++)
    if (g[i] == p && g[i + 3] == p && g[i + 6] == p) return true;
  if (g[0] == p && g[4] == p && g[8] == p) return true;
  if (g[2] == p && g[4] == p && g[6] == p) return true;
  return false;
}
void search(int t) {
  if (pan(g, 'X')) {
    m[did(g)] = "the first player won";
    return;
  }
  if (pan(g, '0')) {
    m[did(g)] = "the second player won";
    return;
  }
  if (t == 9) {
    m[did(g)] = "draw";
    return;
  }
  if (t % 2 == 0) m[did(g)] = "first";
  if (t % 2 == 1) m[did(g)] = "second";
  for (int i = 0; i < 9; i++) {
    if (g[i] == '.') {
      if (t % 2 == 1)
        g[i] = '0';
      else
        g[i] = 'X';
      search(t + 1);
      g[i] = '.';
    }
  }
}
int main() {
  search(0);
  for (int i = 0; i < 3; i++) {
    string ss;
    cin >> ss;
    s += ss;
  }
  int p = did(s);
  if (m[p] == "")
    cout << "illegal";
  else
    cout << m[p] << endl;
  return 0;
}
