#include <bits/stdc++.h>
using namespace std;
bool check(char s[9], char c) {
  if ((s[0] == s[1] && s[0] == s[2] && s[0] == c) ||
      (s[3] == s[4] && s[3] == s[5] && s[3] == c) ||
      (s[6] == s[7] && s[6] == s[8] && s[6] == c) ||
      (s[0] == s[3] && s[0] == s[6] && s[0] == c) ||
      (s[1] == s[4] && s[1] == s[7] && s[1] == c) ||
      (s[2] == s[5] && s[2] == s[8] && s[2] == c) ||
      (s[0] == s[4] && s[0] == s[8] && s[0] == c) ||
      (s[2] == s[4] && s[2] == s[6] && s[2] == c))
    return true;
  return false;
}
string XO(char s[9]) {
  int x = 0, o = 0;
  for (int i = 0; i < 9; i++) {
    if (s[i] == 'X')
      x++;
    else if (s[i] == '0')
      o++;
  }
  if (x - o == 0 || x - o == 1) {
    if (check(s, 'X') && check(s, '0')) return "illegal";
    if (check(s, 'X')) {
      if (x - o == 1)
        return "the first player won";
      else
        return "illegal";
    } else if (check(s, '0')) {
      if (x - o == 0)
        return "the second player won";
      else
        return "illegal";
    } else {
      if (x == 5 && o == 4)
        return "draw";
      else if (x - o == 0)
        return "first";
      else if (x - o == 1)
        return "second";
    }
  } else
    return "illegal";
}
int main() {
  char s[9];
  cin >> s[0] >> s[1] >> s[2];
  cin >> s[3] >> s[4] >> s[5];
  cin >> s[6] >> s[7] >> s[8];
  cout << XO(s) << "\n";
  return 0;
}
