#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, l, n = 3, m, f1 = 0, f2 = 0, blank = 0, cnt = 0,
                            cnt0 = 0, cntx = 0;
  string s[3];
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      if (s[i][j] != '.') {
        if (s[i][j] == '0') {
          cnt0++;
        } else if (s[i][j] == 'X') {
          cntx++;
        }
        cnt++;
      } else if (s[i][j] == '.') {
        blank++;
      }
    }
  }
  if (cnt0 > cntx) {
    cout << "illegal";
    return 0;
  } else if (cntx > cnt0 + 1) {
    cout << "illegal";
    return 0;
  }
  if (s[0][1] == s[0][0] && s[0][1] == s[0][2] && s[0][1] == '0') {
    f2++;
  } else if (s[0][1] == s[0][0] && s[0][1] == s[0][2] && s[0][1] == 'X') {
    f1++;
  }
  if (s[1][0] == s[0][0] && s[2][0] == s[0][0] && s[1][0] == '0') {
    f2++;
  } else if (s[1][0] == s[0][0] && s[2][0] == s[0][0] && s[1][0] == 'X') {
    f1++;
  }
  if (s[1][2] == s[0][2] && s[2][2] == s[1][2] && s[1][2] == '0') {
    f2++;
  } else if (s[1][2] == s[0][2] && s[2][2] == s[1][2] && s[1][2] == 'X') {
    f1++;
  }
  if (s[2][1] == s[2][0] && s[2][1] == s[2][2] && s[2][1] == '0') {
    f2++;
  } else if (s[2][1] == s[2][0] && s[2][2] == s[2][1] && s[2][1] == 'X') {
    f1++;
  }
  if (s[1][1] == s[0][1] && s[1][1] == s[2][1] && s[1][1] == '0') {
    f2++;
  } else if (s[1][1] == s[0][1] && s[1][1] == s[2][1] && s[1][1] == 'X') {
    f1++;
  }
  if (s[1][1] == s[1][0] && s[1][1] == s[1][2] && s[1][1] == '0') {
    f2++;
  } else if (s[1][1] == s[1][0] && s[1][1] == s[1][2] && s[1][1] == 'X') {
    f1++;
  }
  if (s[1][1] == s[2][2] && s[1][1] == s[0][0] && s[1][1] == '0') {
    f2++;
  } else if (s[1][1] == s[0][0] && s[1][1] == s[2][2] && s[1][1] == 'X') {
    f1++;
  }
  if (s[1][1] == s[0][2] && s[1][1] == s[2][0] && s[1][1] == '0') {
    f2++;
  } else if (s[1][1] == s[0][2] && s[1][1] == s[2][0] && s[1][1] == 'X') {
    f1++;
  }
  if (f1 > 0 && f2 > 0) {
    cout << "illegal";
    return 0;
  }
  if (f2 == 1 && f1 == 0 && cntx == cnt0) {
    cout << "the second player won";
    return 0;
  }
  if (f2 == 1 && f1 == 0 && cntx == cnt0 + 1) {
    cout << "illegal";
    return 0;
  }
  if (f2 == 2 && f1 == 0) {
    cout << "the second player won";
    return 0;
  }
  if (f1 == 1 && f2 == 0 && cnt0 + 1 == cntx) {
    cout << "the first player won";
    return 0;
  }
  if (f1 == 1 && f2 == 0 && cnt0 == cntx) {
    cout << "illegal";
    return 0;
  }
  if (f1 == 2 && f2 == 0) {
    cout << "the first player won";
    return 0;
  }
  if (blank == 0) {
    cout << "draw";
    return 0;
  }
  if (cnt % 2 == 1) {
    cout << "second";
    return 0;
  } else {
    cout << "first";
  }
}
