#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 9;
const long long N = 500500;
char s[4][4];
long long dot, cross, nought, first_wins, second_wins;
long long first_win_rows, first_win_col, second_win_row, second_win_col;
long long total;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for (long long i = 1; i <= 3; i++) {
    for (long long j = 1; j <= 3; j++) {
      cin >> s[i][j];
      if (s[i][j] == '.') dot++;
      if (s[i][j] == 'X') cross++;
      if (s[i][j] == '0') nought++;
    }
  }
  total += cross + nought;
  if (!(cross == nought || cross == nought + 1)) {
    cout << "illegal";
    return 0;
  }
  for (long long i = 1; i <= 3; i++) {
    set<char> st;
    for (long long j = 1; j <= 3; j++) {
      st.insert(s[i][j]);
    }
    if (st.size() == 1 && *st.begin() == 'X') {
      first_wins++;
    }
    if (st.size() == 1 && *st.begin() == '0') {
      second_wins++;
    }
  }
  for (long long j = 1; j <= 3; j++) {
    set<char> st;
    for (long long i = 1; i <= 3; i++) {
      st.insert(s[i][j]);
    }
    if (st.size() == 1 && *st.begin() == 'X') {
      first_wins++;
    }
    if (st.size() == 1 && *st.begin() == '0') {
      second_wins++;
    }
  }
  set<char> st;
  st.insert(s[1][1]);
  st.insert(s[2][2]);
  st.insert(s[3][3]);
  if (st.size() == 1 && *st.begin() == 'X') {
    first_wins++;
  }
  if (st.size() == 1 && *st.begin() == '0') {
    second_wins++;
  }
  st.clear();
  st.insert(s[1][3]);
  st.insert(s[2][2]);
  st.insert(s[3][1]);
  if (st.size() == 1 && *st.begin() == 'X') {
    first_wins++;
  }
  if (st.size() == 1 && *st.begin() == '0') {
    second_wins++;
  }
  if (first_wins > 0 && second_wins > 0) {
    cout << "illegal";
    return 0;
  }
  if (first_wins > 0 || second_wins > 0) {
    if (first_wins == 1 && total & 1) {
      cout << "the first player won";
    } else if (second_wins == 1 && total % 2 == 0) {
      cout << "the second player won";
    } else if (first_wins == 2 && total & 1) {
      if (first_win_col == 2 || first_win_rows == 2) {
        cout << "illegal";
      } else {
        cout << "the first player won";
      }
    } else if (second_wins == 2 && total % 2 == 0) {
      if (second_win_col == 2 || second_win_row == 2) {
        cout << "illegal";
      } else {
        cout << "the second player won";
      }
    } else {
      cout << "illegal";
    }
    return 0;
  }
  if (dot > 0) {
    if (cross == nought)
      cout << "first";
    else
      cout << "second";
  } else {
    cout << "draw";
  }
  return 0;
}
