#include <bits/stdc++.h>
using namespace std;
char c[10][10];
char chFirst;
char chSecond;
int nFirst;
int nSecond;
void getFirst() {
  chFirst = 'X';
  chSecond = '0';
  nFirst = 0;
  nSecond = 0;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      if (c[i][j] == chFirst)
        nFirst++;
      else if (c[i][j] == chSecond)
        nSecond++;
    }
}
int step[4][2] = {0, -1, -1, -1, -1, 0, -1, 1};
inline int judge(int x, int y) { return x >= 0 && x < 3 && y >= 0 && y < 3; }
int dfs(int x, int y, int xd, int yd) {
  int xx = x + xd;
  int yy = y + yd;
  if (!judge(xx, yy)) return 1;
  if (c[xx][yy] != c[x][y]) return 1;
  return dfs(xx, yy, xd, yd) + 1;
}
bool check(char ch) {
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      if (c[i][j] != ch) continue;
      for (int k = 0; k < 4; k++) {
        if (dfs(i, j, step[k][0], step[k][1]) +
                dfs(i, j, -step[k][0], -step[k][1]) - 1 ==
            3)
          return true;
      }
    }
  return false;
}
void solve() {
  getFirst();
  if (nFirst > nSecond + 1 || nSecond > nFirst) {
    cout << "illegal" << endl;
    return;
  }
  if (check(chFirst) && nSecond >= nFirst ||
      check(chSecond) && nFirst > nSecond) {
    cout << "illegal" << endl;
    return;
  }
  if (check(chFirst)) {
    cout << "the first player won" << endl;
    return;
  }
  if (check(chSecond)) {
    cout << "the second player won" << endl;
    return;
  }
  if (nFirst + nSecond == 9) {
    cout << "draw" << endl;
    return;
  }
  if (nFirst == nSecond) {
    cout << "first" << endl;
    return;
  }
  cout << "second" << endl;
}
int main() {
  for (int i = 0; i < 3; i++) scanf("%s", c[i]);
  solve();
  return 0;
}
