#include <bits/stdc++.h>
using namespace std;
char s[4][4];
void solve() {
  int cnt0 = 0, cnt1 = 0;
  for (int i = 0; i < 3; ++i) {
    scanf("%s", s[i]);
    for (int j = 0; j < 3; ++j)
      if (s[i][j] == 'X')
        ++cnt0;
      else if (s[i][j] == '0')
        ++cnt1;
  }
  int t0 = cnt0, t1 = cnt1;
  cnt0 = 0;
  cnt1 = 0;
  for (int i = 0; i < 3; ++i) {
    if (s[i][0] == s[i][1] && s[i][0] == s[i][2]) {
      if (s[i][0] == '0') ++cnt1;
      if (s[i][0] == 'X') ++cnt0;
    }
    if (s[0][i] == s[1][i] && s[0][i] == s[2][i]) {
      if (s[0][i] == '0') ++cnt1;
      if (s[0][i] == 'X') ++cnt0;
    }
  }
  if (s[0][0] == s[1][1] && s[1][1] == s[2][2]) {
    if (s[1][1] == '0') ++cnt1;
    if (s[1][1] == 'X') ++cnt0;
  }
  if (s[0][2] == s[1][1] && s[1][1] == s[2][0]) {
    if (s[1][1] == '0') ++cnt1;
    if (s[1][1] == 'X') ++cnt0;
  }
  if ((cnt0 && cnt1) || t1 > t0 || t1 + 1 < t0 || (cnt0 && t1 == t0) ||
      (cnt1 && t0 > t1)) {
    puts("illegal");
    return;
  }
  if (cnt0) {
    puts("the first player won");
    return;
  } else if (cnt1) {
    puts("the second player won");
    return;
  }
  if (t0 + t1 != 9) {
    if (t0 == t1)
      puts("first");
    else
      puts("second");
    return;
  }
  if (!cnt1 && !cnt0) puts("draw");
}
int main() {
  solve();
  return 0;
}
