#include <bits/stdc++.h>
using namespace std;
string str[3];
void init() { cin >> str[0] >> str[1] >> str[2]; }
void solve() {
  int cnt1(0), cnt2(0);
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (str[i][j] == 'X')
        cnt1++;
      else if (str[i][j] == '0')
        cnt2++;
    }
  }
  if (cnt1 - cnt2 < 0 || cnt1 - cnt2 > 1) {
    printf("illegal\n");
    return;
  }
  for (int i = 0; i < 3; i++) {
    if (str[i][0] == str[i][1] && str[i][1] == str[i][2]) {
      if (str[i][0] == 'X') {
        if (cnt1 > cnt2) {
          printf("the first player won\n");
        } else {
          printf("illegal\n");
        }
        return;
      } else if (str[i][0] == '0') {
        if (cnt1 == cnt2) {
          printf("the second player won\n");
        } else {
          printf("illegal\n");
        }
        return;
      }
    }
    if (str[0][i] == str[1][i] && str[1][i] == str[2][i]) {
      if (str[0][i] == 'X') {
        if (cnt1 > cnt2) {
          printf("the first player won\n");
        } else {
          printf("illegal\n");
        }
        return;
      } else if (str[0][i] == '0') {
        if (cnt1 == cnt2) {
          printf("the second player won\n");
        } else {
          printf("illegal\n");
        }
        return;
      }
    }
  }
  if (str[0][0] == str[1][1] && str[1][1] == str[2][2]) {
    if (str[0][0] == 'X') {
      if (cnt1 > cnt2) {
        printf("the first player won\n");
      } else {
        printf("illegal\n");
      }
      return;
    } else if (str[0][0] == '0') {
      if (cnt1 == cnt2) {
        printf("the second player won\n");
      } else {
        printf("illegal\n");
      }
      return;
    }
  }
  if (str[0][2] == str[1][1] && str[1][1] == str[2][0]) {
    if (str[0][2] == 'X') {
      if (cnt1 > cnt2) {
        printf("the first player won\n");
      } else {
        printf("illegal\n");
      }
      return;
    } else if (str[0][2] == '0') {
      if (cnt1 == cnt2) {
        printf("the second player won\n");
      } else {
        printf("illegal\n");
      }
      return;
    }
  }
  if (cnt1 == cnt2) {
    printf("first\n");
  } else if (cnt2 < 4) {
    printf("second\n");
  } else {
    printf("draw\n");
  }
}
int main() {
  init();
  solve();
  return 0;
}
