#include <bits/stdc++.h>
using namespace std;
bool PlayerWins(string b[], char sym) {
  for (int i = 0; i < 3; i++) {
    bool hor = true, ver = true;
    for (int j = 0; j < 3; j++) {
      if (b[i][j] != sym) hor = false;
      if (b[j][i] != sym) ver = false;
    }
    if (hor || ver) {
      return true;
    }
  }
  if (b[0][0] == b[1][1] && b[1][1] == b[2][2] && b[0][0] == sym) {
    return true;
  }
  if (b[2][0] == b[1][1] && b[1][1] == b[0][2] && b[2][0] == sym) {
    return true;
  }
  return false;
}
bool IsFilled(string b[]) {
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (b[i][j] == '.') {
        return false;
      }
    }
  }
  return true;
}
int Count(string b[], char sym) {
  int s = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (b[i][j] == sym) {
        s += 1;
      }
    }
  }
  return s;
}
string x[3];
string goal[3];
bool legal = false;
void Search(char s) {
  if (x[0] == goal[0] && x[1] == goal[1] && x[2] == goal[2]) {
    legal = true;
    return;
  }
  if (PlayerWins(x, 'X') || PlayerWins(x, '0') || IsFilled(x)) {
    return;
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (x[i][j] != '.') {
        continue;
      }
      char next = (s == 'X' ? '0' : 'X');
      x[i][j] = s;
      Search(next);
      x[i][j] = '.';
      if (legal) {
        return;
      }
    }
  }
}
bool IsLegal(string b[]) {
  for (int i = 0; i < 3; i++) {
    goal[i] = b[i];
  }
  x[0] = "...";
  x[1] = "...";
  x[2] = "...";
  legal = false;
  Search('X');
  return legal;
}
string Verdict(string b[]) {
  int m = Count(b, 'X');
  int n = Count(b, '0');
  if (!IsLegal(b)) {
    return "illegal";
  } else if (PlayerWins(b, 'X')) {
    return "the first player won";
  } else if (PlayerWins(b, '0')) {
    return "the second player won";
  } else if (IsFilled(b)) {
    return "draw";
  } else if (m > n) {
    return "second";
  } else {
    return "first";
  }
}
int main(void) {
  string b[3];
  for (int i = 0; i < 3; i++) {
    cin >> b[i];
  }
  cout << Verdict(b) << endl;
  return EXIT_SUCCESS;
}
