#include <bits/stdc++.h>
int main() {
  char a[5][5];
  int i, j, k;
  int F, S, D;
  int ying1, ying2;
  ying1 = ying2 = 0;
  F = S = 0;
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      scanf("%c", &a[i][j]);
      if (a[i][j] == 'X') F++;
      if (a[i][j] == '0') S++;
      if (a[i][j] == '.') D++;
    }
    getchar();
  }
  if (D + S + F != 9) {
    printf("illegal\n");
    return 0;
  }
  if (F > S + 1 || F < S) {
    printf("illegal\n");
  } else {
    for (i = 0; i < 3; i++)
      if (a[i][0] == a[i][1] && a[i][0] == a[i][2] && a[i][0] == 'X') ying1 = 1;
    for (i = 0; i < 3; i++)
      if (a[0][i] == a[1][i] && a[0][i] == a[2][i] && a[0][i] == 'X') ying1 = 1;
    if (a[0][0] == a[1][1] && a[1][1] == a[2][2] && a[0][0] == 'X') ying1 = 1;
    if (a[2][0] == a[1][1] && a[2][0] == a[0][2] && a[1][1] == 'X') ying1 = 1;
    for (i = 0; i < 3; i++)
      if (a[i][0] == a[i][1] && a[i][0] == a[i][2] && a[i][0] == '0') ying2 = 1;
    for (i = 0; i < 3; i++)
      if (a[0][i] == a[1][i] && a[0][i] == a[2][i] && a[0][i] == '0') ying2 = 1;
    if (a[0][0] == a[1][1] && a[1][1] == a[2][2] && a[0][0] == '0') ying2 = 1;
    if (a[2][0] == a[1][1] && a[2][0] == a[0][2] && a[1][1] == '0') ying2 = 1;
    if (ying1 == 1 && ying2 == 1)
      printf("illegal\n");
    else if (ying1 == 0 && ying2 == 1) {
      if (F == S)
        printf("the second player won\n");
      else
        printf("illegal\n");
    } else if (ying1 == 1 && ying2 == 0) {
      if (F == S + 1)
        printf("the first player won\n");
      else
        printf("illegal\n");
    } else if (ying1 == 0 && ying2 == 0) {
      if (F == 5 && S == 4)
        printf("draw\n");
      else if (F == S)
        printf("first\n");
      else if (F > S)
        printf("second\n");
    }
  }
  return 0;
}
