#include <bits/stdc++.h>
using namespace std;
string s[4];
int x = 0, o = 0;
bool thangx = 0, thango = 0;
void nhap() {
  for (int i = 1; i <= 3; i++) {
    cin >> s[i];
    s[i] = "*" + s[i];
    for (int j = 1; j <= 3; j++) {
      if (s[i][j] == 'X')
        x++;
      else if (s[i][j] == '0')
        o++;
    }
  }
}
void xuli() {
  for (int i = 1; i <= 3; i++) {
    if (s[1][i] == 'X') {
      if (i == 1) {
        if (s[2][2] == 'X' && s[3][3] == 'X' ||
            s[2][1] == 'X' && s[3][1] == 'X')
          thangx = 1;
      } else if (i == 2 && s[3][2] == 'X' && s[2][2] == 'X')
        thangx = 1;
      else if (i == 3) {
        if (s[2][2] == 'X' && s[3][1] == 'X' ||
            s[2][3] == 'X' && s[3][3] == 'X')
          thangx = 1;
      }
    } else if (s[1][i] == '0') {
      if (i == 1) {
        if (s[2][2] == '0' && s[3][3] == '0' ||
            s[2][1] == '0' && s[3][1] == '0')
          thango = 1;
      } else if (i == 2 && s[3][2] == '0' && s[2][2] == '0')
        thango = 1;
      else if (i == 3) {
        if (s[2][2] == '0' && s[3][1] == '0' ||
            s[2][3] == '0' && s[3][3] == '0')
          thango = 1;
      }
    }
    if (s[i][1] == s[i][2] && s[i][2] == s[i][3]) {
      thangx = max(thangx, (s[i][1] == 'X'));
      thango = max(thango, (s[i][1] == '0'));
    }
  }
}
void ghi() {
  if (x > (o + 1) || o > x || thangx == 1 && thango == 1 ||
      thango == 1 && x > o || thangx == 1 && x == o) {
    cout << "illegal";
    return;
  }
  if (thangx == 1 && thango == 0) {
    cout << "the first player won";
    return;
  } else if (thangx == 0 && thango == 1) {
    cout << "the second player won";
    return;
  } else if (x == 5 && o == 4 && thangx == 0 && thango == 0) {
    cout << "draw";
    return;
  }
  if (x > o)
    cout << "second";
  else if (x == o)
    cout << "first";
  return;
}
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  nhap();
  xuli();
  ghi();
  return 0;
}
