#include <bits/stdc++.h>
using namespace std;
map<string, string> m;
string a = ".........";
inline int judge() {
  for (int i = 0; i < 3; i++) {
    if (a[3 * i] != '.')
      if (a[3 * i] == a[3 * i + 1] && a[3 * i] == a[3 * i + 2]) return 3 * i;
    if (a[i] != '.')
      if (a[i] == a[i + 3] && a[i] == a[i + 6]) return i;
  }
  if (a[4] == '.')
    return -1;
  else if ((a[0] == a[4] && a[4] == a[8]) || (a[2] == a[4] && a[4] == a[6]))
    return 4;
  return -1;
}
void search(int n) {
  int s;
  s = judge();
  if (s != -1) {
    m[a] = (a[s] == 'X' ? "the first player won" : "the second player won");
    return;
  } else if (n == 9) {
    m[a] = "draw";
    return;
  } else {
    m[a] = (n % 2 == 0 ? "first" : "second");
    for (int i = 0; i < 9; i++)
      if (a[i] == '.') {
        a[i] = (n % 2 == 0 ? 'X' : '0');
        search(n + 1);
        a[i] = '.';
      }
  }
}
int main() {
  search(0);
  string str1, str2, str3;
  cin >> str1 >> str2 >> str3;
  a = str1 + str2 + str3;
  if (m[a] != "")
    cout << m[a] << endl;
  else
    cout << "illegal" << endl;
  return 0;
}
