#include <bits/stdc++.h>
using namespace std;
char g[3][3];
bool check(char c) {
  for (int i = 0; i < 3; ++i) {
    int win = 1;
    for (int j = 0; j < 3; ++j)
      if (g[i][j] != c) win = 0;
    if (win) return win;
  }
  for (int i = 0; i < 3; ++i) {
    int win = 1;
    for (int j = 0; j < 3; ++j)
      if (g[j][i] != c) win = 0;
    if (win) return win;
  }
  if (g[0][0] == c && g[1][1] == c && g[2][2] == c) return true;
  if (g[0][2] == c && g[1][1] == c && g[2][0] == c) return true;
  return false;
}
int work() {
  for (int i = 0; i < 3; ++i) scanf("%s", g[i]);
  int X = 0, O = 0;
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j)
      if (g[i][j] == '0')
        ++O;
      else if (g[i][j] == 'X')
        ++X;
  int winX = check('X'), winO = check('0');
  if (winX && winO) return puts("illegal") * 0;
  if (X != O + 1 && X != O) return puts("illegal") * 0;
  if (winX && X != O + 1) return puts("illegal") * 0;
  if (winO && O != X) return puts("illegal") * 0;
  if (winX) return puts("the first player won") * 0;
  if (winO) return puts("the second player won") * 0;
  if (X + O == 9) return puts("draw") * 0;
  if (X == O) return puts("first") * 0;
  if (X == O + 1) return puts("second") * 0;
}
int32_t main() { work(); }
