#include <bits/stdc++.h>
using namespace std;
char s[5][5];
int r[4][2], c[4][2];
int main() {
  int i, j;
  memset(r, 0, sizeof(r));
  memset(c, 0, sizeof(c));
  for (i = 0; i < 3; ++i) scanf("%s", s[i]);
  for (i = 0; i < 3; ++i)
    for (j = 0; j < 3; ++j) {
      if (s[i][j] == 'X') {
        r[i][0]++;
        c[j][0]++;
      }
      if (s[i][j] == '0') {
        r[i][1]++;
        c[j][1]++;
      }
    }
  bool flag = 1, flag1 = 0, flag2 = 0;
  int t1 = 0, t2 = 0;
  for (i = 0; i < 3; ++i)
    for (j = 0; j < 3; ++j) {
      if (s[i][j] == 'X') ++t1;
      if (s[i][j] == '0') ++t2;
    }
  if (t1 - t2 < 0 || t1 - t2 > 1) flag = 0;
  if (s[0][0] == s[1][1] && s[1][1] == s[2][2] && s[0][0] == 'X') flag1 = 1;
  if (s[2][0] == s[1][1] && s[1][1] == s[0][2] && s[1][1] == 'X') flag1 = 1;
  if (s[0][0] == s[1][1] && s[1][1] == s[2][2] && s[0][0] == '0') flag2 = 1;
  if (s[2][0] == s[1][1] && s[1][1] == s[0][2] && s[1][1] == '0') flag2 = 1;
  for (i = 0; i < 3 && flag && !flag1; ++i) {
    if (r[i][0] == 3) flag1 = 1;
    if (c[i][0] == 3) flag1 = 1;
  }
  for (i = 0; i < 3 && flag && !flag2; ++i) {
    if (r[i][1] == 3) flag2 = 1;
    if (c[i][1] == 3) flag2 = 1;
  }
  if (!flag)
    puts("illegal");
  else if (flag1 && flag2)
    puts("illegal");
  else if (t1 != t2 && flag2)
    puts("illegal");
  else if (t1 == t2 && flag1)
    puts("illegal");
  else if (flag1)
    puts("the first player won");
  else if (flag2)
    puts("the second player won");
  else {
    if (t1 + t2 == 9)
      puts("draw");
    else if (t1 > t2)
      puts("second");
    else if (t1 == t2)
      puts("first");
  }
  return 0;
}
