#include <bits/stdc++.h>
using namespace std;
const int N = 1000006;
char T[4][4];
int n, k;
int solve() {
  int nx = 0, no = 0;
  bool wx = false, wo = false;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
      if (T[i][j] == 'X')
        nx++;
      else if (T[i][j] == '0')
        no++;
  bool iden;
  for (int i = 0; i < 3; i++) {
    iden = true;
    for (int j = 1; j < 3; j++)
      if (T[i][j] != T[i][j - 1]) iden = false;
    if (iden && T[i][0] == 'X') wx = true;
    if (iden && T[i][0] == '0') wo = true;
  }
  for (int i = 0; i < 3; i++) {
    iden = true;
    for (int j = 1; j < 3; j++)
      if (T[j][i] != T[j - 1][i]) iden = false;
    if (iden && T[0][i] == 'X') wx = true;
    if (iden && T[0][i] == '0') wo = true;
  }
  iden = true;
  for (int j = 1; j < 3; j++)
    if (T[j][j] != T[j - 1][j - 1]) iden = false;
  if (iden && T[0][0] == 'X') wx = true;
  if (iden && T[0][0] == '0') wo = true;
  iden = true;
  for (int j = 1; j < 3; j++)
    if (T[2 - j][j] != T[3 - j][j - 1]) iden = false;
  if (iden && T[0][2] == 'X') wx = true;
  if (iden && T[0][2] == '0') wo = true;
  if (wo && wx) return 2;
  if (no > nx || nx > no + 1) return 2;
  if (wo && no != nx) return 2;
  if (wx && no != nx - 1) return 2;
  if (wo) return 4;
  if (wx) return 3;
  if (nx + no == 9) return 5;
  if (no == nx) return 0;
  return 1;
}
int main() {
  for (int i = 0; i < 3; i++) scanf(" %s", T[i]);
  switch (solve()) {
    case 0:
      printf("first\n");
      break;
    case 1:
      printf("second\n");
      break;
    case 2:
      printf("illegal\n");
      break;
    case 3:
      printf("the first player won\n");
      break;
    case 4:
      printf("the second player won\n");
      break;
    case 5:
      printf("draw\n");
      break;
  }
  return 0;
}
