#include <bits/stdc++.h>
int main() {
  using namespace std;
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  char grid[3][3];
  int cnt_X = 0, cnt_0 = 0;
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> grid[i][j];
      if (grid[i][j] == 'X') ++cnt_X;
      if (grid[i][j] == '0') ++cnt_0;
    }
    cin.get();
  }
  if (cnt_X < cnt_0 || cnt_X > cnt_0 + 1) {
    cout << "illegal";
    exit(0);
  }
  int illegal = 0;
  vector<pair<int, int>> ans;
  for (int i = 0; i < 3; ++i) {
    if (grid[i][0] != '.' && grid[i][0] == grid[i][1] &&
        grid[i][0] == grid[i][2]) {
      ++illegal, ans.emplace_back(make_pair(i, 0));
    }
  }
  for (int i = 0; i < 3; ++i) {
    if (grid[0][i] != '.' && grid[0][i] == grid[1][i] &&
        grid[0][i] == grid[2][i]) {
      ++illegal, ans.emplace_back(make_pair(0, i));
    }
  }
  if (grid[0][0] != '.' && grid[0][0] == grid[1][1] && grid[0][0] == grid[2][2])
    ++illegal, ans.emplace_back(make_pair(1, 1));
  if (grid[0][2] != '.' && grid[0][2] == grid[1][1] && grid[0][2] == grid[2][0])
    ++illegal, ans.emplace_back(make_pair(1, 1));
  if (illegal > 2) {
    cout << "illegal";
    exit(0);
  }
  if (illegal == 1) {
    if (grid[ans[0].first][ans[0].second] == 'X') {
      if (cnt_X > cnt_0) {
        cout << "the first player won";
        exit(0);
      }
    } else {
      if (cnt_X == cnt_0) {
        cout << "the second player won";
        exit(0);
      }
    }
    cout << "illegal";
    exit(0);
  } else if (illegal == 2) {
    if (grid[ans[0].first][ans[0].second] == 'X' &&
        grid[ans[1].first][ans[1].second] == 'X') {
      if (ans[0] == ans[1]) {
        cout << "the first player won";
        exit(0);
      } else if (ans[0].first == 0 && ans[1].second == 0) {
        cout << "the first player won";
        exit(0);
      } else if (ans[1].first == 0 && ans[0].second == 0) {
        cout << "the first player won";
        exit(0);
      } else if (ans[0].first && ans[0].second) {
        cout << "the first player won";
        exit(0);
      } else if (ans[1].first && ans[1].second) {
        cout << "the first player won";
        exit(0);
      }
    }
    cout << "illegal";
    exit(0);
  }
  if (cnt_X + cnt_0 == 9) {
    cout << "draw";
    exit(0);
  }
  if (cnt_X == cnt_0) {
    cout << "first";
  } else {
    cout << "second";
  }
}
