#include <bits/stdc++.h>
char maze[3][4];
bool iswin(char c) {
  for (int i = 0; i < 3; ++i) {
    if (maze[i][0] == maze[i][1] && maze[i][0] == maze[i][2] && maze[i][0] == c)
      return true;
  }
  for (int i = 0; i < 3; ++i) {
    if (maze[0][i] == maze[1][i] && maze[0][i] == maze[2][i] && maze[0][i] == c)
      return true;
  }
  if (maze[0][0] == maze[1][1] && maze[0][0] == maze[2][2] && maze[0][0] == c)
    return true;
  if (maze[0][2] == maze[1][1] && maze[0][2] == maze[2][0] && maze[0][2] == c)
    return true;
  return false;
}
int main() {
  for (int i = 0; i < 3; ++i) {
    scanf("%s", maze[i]);
  }
  int cx = 0, co = 0;
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (maze[i][j] == '0') {
        ++co;
      } else if (maze[i][j] == 'X') {
        ++cx;
      }
    }
  }
  bool xfirst = false;
  if (cx == co) {
    xfirst = true;
  } else if (cx == co + 1) {
    xfirst = false;
  } else {
    puts("illegal");
    return 0;
  }
  bool winx = iswin('X');
  bool wino = iswin('0');
  if (winx && wino) {
    puts("illegal");
    return 0;
  }
  if (winx && xfirst == true) {
    puts("illegal");
    return 0;
  }
  if (wino && xfirst == false) {
    puts("illegal");
    return 0;
  }
  if (winx || wino) {
    if (winx) {
      bool isok = false;
      for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
          if (maze[i][j] == 'X') {
            maze[i][j] = '.';
            if (!iswin('X')) {
              isok = true;
              goto e1;
            }
            maze[i][j] = 'X';
          }
        }
      }
    e1:
      if (isok) {
        puts("the first player won");
      } else {
        puts("illegal");
      }
    } else {
      bool isok = false;
      for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
          if (maze[i][j] == '0') {
            maze[i][j] = '.';
            if (!iswin('0')) {
              isok = true;
              goto e2;
            }
            maze[i][j] = '0';
          }
        }
      }
    e2:
      if (isok) {
        puts("the second player won");
      } else {
        puts("illegal");
      }
    }
  } else {
    if (cx + co == 9) {
      puts("draw");
    } else if (xfirst) {
      puts("first");
    } else {
      puts("second");
    }
  }
  return 0;
}
