#include <bits/stdc++.h>
using namespace std;
int n, h, i, s, a[1010];
int main() {
  char ch[3][3];
  int cnt1 = 0, cnt2 = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> ch[i][j];
      if (ch[i][j] == 'X') cnt1++;
      if (ch[i][j] == '0') cnt2++;
    }
  }
  if (cnt1 - cnt2 > 1 || cnt1 < cnt2) {
    cout << "illegal" << endl;
    return 0;
  }
  int flag1 = 0, flag2 = 0;
  if (cnt1 > cnt2) {
    if ((ch[0][0] == 'X' && ch[0][1] == 'X' && ch[0][2] == 'X') ||
        (ch[1][0] == 'X' && ch[1][1] == 'X' && ch[1][2] == 'X') ||
        (ch[2][0] == 'X' && ch[2][1] == 'X' && ch[2][2] == 'X') ||
        (ch[0][0] == 'X' && ch[1][0] == 'X' && ch[2][0] == 'X') ||
        (ch[0][1] == 'X' && ch[1][1] == 'X' && ch[2][1] == 'X') ||
        (ch[0][2] == 'X' && ch[1][2] == 'X' && ch[2][2] == 'X') ||
        (ch[0][0] == 'X' && ch[1][1] == 'X' && ch[2][2] == 'X') ||
        (ch[2][0] == 'X' && ch[1][1] == 'X' && ch[0][2] == 'X'))
      flag1 = 1;
    if ((ch[0][0] == '0' && ch[0][1] == '0' && ch[0][2] == '0') ||
        (ch[1][0] == '0' && ch[1][1] == '0' && ch[1][2] == '0') ||
        (ch[2][0] == '0' && ch[2][1] == '0' && ch[2][2] == '0') ||
        (ch[0][0] == '0' && ch[1][0] == '0' && ch[2][0] == '0') ||
        (ch[0][1] == '0' && ch[1][1] == '0' && ch[2][1] == '0') ||
        (ch[0][2] == '0' && ch[1][2] == '0' && ch[2][2] == '0') ||
        (ch[0][0] == '0' && ch[1][1] == '0' && ch[2][2] == '0') ||
        (ch[2][0] == '0' && ch[1][1] == '0' && ch[0][2] == '0'))
      flag2 = 1;
    if (flag2 == 1) cout << "illegal" << endl;
    if (flag1 == 1 && flag2 == 0) cout << "the first player won" << endl;
    if (flag1 == 0 && flag2 == 0 && cnt1 + cnt2 != 9) cout << "second" << endl;
    if (flag1 == 0 && flag2 == 0 && cnt1 + cnt2 == 9) cout << "draw" << endl;
  }
  if (cnt1 == cnt2) {
    if ((ch[0][0] == 'X' && ch[0][1] == 'X' && ch[0][2] == 'X') ||
        (ch[1][0] == 'X' && ch[1][1] == 'X' && ch[1][2] == 'X') ||
        (ch[2][0] == 'X' && ch[2][1] == 'X' && ch[2][2] == 'X') ||
        (ch[0][0] == 'X' && ch[1][0] == 'X' && ch[2][0] == 'X') ||
        (ch[0][1] == 'X' && ch[1][1] == 'X' && ch[2][1] == 'X') ||
        (ch[0][2] == 'X' && ch[1][2] == 'X' && ch[2][2] == 'X') ||
        (ch[0][0] == 'X' && ch[1][1] == 'X' && ch[2][2] == 'X') ||
        (ch[2][0] == 'X' && ch[1][1] == 'X' && ch[0][2] == 'X'))
      flag1 = 1;
    if ((ch[0][0] == '0' && ch[0][1] == '0' && ch[0][2] == '0') ||
        (ch[1][0] == '0' && ch[1][1] == '0' && ch[1][2] == '0') ||
        (ch[2][0] == '0' && ch[2][1] == '0' && ch[2][2] == '0') ||
        (ch[0][0] == '0' && ch[1][0] == '0' && ch[2][0] == '0') ||
        (ch[0][1] == '0' && ch[1][1] == '0' && ch[2][1] == '0') ||
        (ch[0][2] == '0' && ch[1][2] == '0' && ch[2][2] == '0') ||
        (ch[0][0] == '0' && ch[1][1] == '0' && ch[2][2] == '0') ||
        (ch[2][0] == '0' && ch[1][1] == '0' && ch[0][2] == '0'))
      flag2 = 1;
    if (flag1 == 1) cout << "illegal" << endl;
    if (flag1 == 0 && flag2 == 1) cout << "the second player won" << endl;
    if (flag1 == 0 && flag2 == 0) cout << "first" << endl;
  }
  return 0;
}
