#include <bits/stdc++.h>
using namespace std;
string g[3];
int t[3][3];
bool first_win() {
  for (int i = 0; i < 3; i++) {
    int sum = 0;
    for (int j = 0; j < 3; j++) sum += t[i][j];
    if (sum == 3) {
      return 1;
    }
  }
  for (int i = 0; i < 3; i++) {
    int sum = 0;
    for (int j = 0; j < 3; j++) sum += t[j][i];
    if (sum == 3) {
      return 1;
    }
  }
  int sum = 0, sum1 = 0;
  for (int i = 0; i < 3; i++) {
    sum += t[i][i];
    sum1 += t[i][2 - i];
  }
  if (sum == 3 || sum1 == 3) {
    return 1;
  }
  return 0;
}
bool second_win() {
  for (int i = 0; i < 3; i++) {
    int sum = 0;
    for (int j = 0; j < 3; j++) sum += t[i][j];
    if (sum == -3) return 1;
  }
  for (int i = 0; i < 3; i++) {
    int sum = 0;
    for (int j = 0; j < 3; j++) sum += t[j][i];
    if (sum == -3) return 1;
  }
  int sum = 0, sum1 = 0;
  for (int i = 0; i < 3; i++) {
    sum += t[i][i];
    sum1 += t[i][2 - i];
  }
  if (sum == -3 || sum1 == -3) return 1;
  return 0;
}
int main() {
  for (int i = 0; i < 3; i++) cin >> g[i];
  int X = 0, O = 0;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < g[i].size(); j++) {
      if (g[i][j] == 'X') X++;
      if (g[i][j] == '0') O++;
    }
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      if (g[i][j] == 'X')
        t[i][j] = 1;
      else if (g[i][j] == '0')
        t[i][j] = -1;
      else
        t[i][j] = 0;
    }
  if (abs(X - O) > 1 || X < O || (first_win() && X == O) ||
      (second_win() && X > O)) {
    cout << "illegal" << endl;
    return 0;
  }
  if (X + O < 9 && !second_win() && !first_win()) {
    if (X == O + 1) cout << "second" << endl;
    if (X == O - 1 || X == O) cout << "first" << endl;
    return 0;
  }
  if (first_win())
    cout << "the first player won" << endl;
  else if (second_win())
    cout << "the second player won" << endl;
  else
    cout << "draw" << endl;
  return 0;
}
