#include <bits/stdc++.h>
using namespace std;
template <class T>
inline string itos(T n) {
  return (n) < 0    ? "-" + itos(-(n))
         : (n) < 10 ? (string)("") + (char)('0' + (n))
                    : itos((n) / 10) + itos((n) % 10);
}
string board[3];
int win(char ch) {
  int i, j, mask = (1 << 9) - 1, cnt = 0;
  vector<int> v;
  for ((i) = 0; (i) < (int)(3); (i)++)
    v.push_back((1 << (i * 3)) + (1 << (i * 3 + 1)) + (1 << (i * 3 + 2)));
  for ((i) = 0; (i) < (int)(3); (i)++)
    v.push_back((1 << (i)) + (1 << (i + 3)) + (1 << (i + 6)));
  v.push_back((1 << (0)) + (1 << (4)) + (1 << (8)));
  v.push_back((1 << (2)) + (1 << (4)) + (1 << (6)));
  int mask2 = 0;
  for ((i) = 0; (i) < (int)(3); (i)++)
    for ((j) = 0; (j) < (int)(3); (j)++)
      if (board[i][j] == ch) mask2 |= (1 << (i * 3 + j));
  for ((i) = 0; (i) < (int)(v.size()); (i)++)
    if ((mask2 & v[i]) == v[i]) {
      cnt++;
    }
  if (cnt == 0) return 0;
  return 1;
}
int count(char ch) {
  int i, j, ans = 0;
  for ((i) = 0; (i) < (int)(3); (i)++)
    for ((j) = 0; (j) < (int)(3); (j)++)
      if (board[i][j] == ch) ans++;
  return ans;
}
string func(void) {
  int A = count('X'), B = count('0');
  if (A < B || A > B + 1) return "illegal";
  int player = ((A == B) ? 0 : 1);
  int wA = win('X'), wB = win('0');
  if (wA == 2 || wB == 2 || (player == 0 && wA == 1) ||
      (player == 1 && wB == 1))
    return "illegal";
  if (wA == 1) return "the first player won";
  if (wB == 1) return "the second player won";
  if (A + B == 9) return "draw";
  if (player == 0) return "first";
  return "second";
}
int main(void) {
  int i;
  for ((i) = 0; (i) < (int)(3); (i)++) cin >> board[i];
  string ans = func();
  cout << ans << endl;
  return 0;
}
