#include <bits/stdc++.h>
using namespace std;
int winner(char arr[3][3]) {
  if ((arr[0][0] == 'X' && arr[0][1] == 'X' && arr[0][2] == 'X') ||
      (arr[1][0] == 'X' && arr[1][1] == 'X' && arr[1][2] == 'X') ||
      (arr[2][0] == 'X' && arr[2][1] == 'X' && arr[2][2] == 'X') ||
      (arr[0][0] == 'X' && arr[1][1] == 'X' && arr[2][2] == 'X') ||
      (arr[0][2] == 'X' && arr[1][1] == 'X' && arr[2][0] == 'X') ||
      (arr[0][0] == 'X' && arr[1][0] == 'X' && arr[2][0] == 'X') ||
      (arr[0][1] == 'X' && arr[1][1] == 'X' && arr[2][1] == 'X') ||
      (arr[0][2] == 'X' && arr[1][2] == 'X' && arr[2][2] == 'X'))
    return 1;
  else if ((arr[0][0] == '0' && arr[0][1] == '0' && arr[0][2] == '0') ||
           (arr[1][0] == '0' && arr[1][1] == '0' && arr[1][2] == '0') ||
           (arr[2][0] == '0' && arr[2][1] == '0' && arr[2][2] == '0') ||
           (arr[0][0] == '0' && arr[1][1] == '0' && arr[2][2] == '0') ||
           (arr[0][2] == '0' && arr[1][1] == '0' && arr[2][0] == '0') ||
           (arr[0][0] == '0' && arr[1][0] == '0' && arr[2][0] == '0') ||
           (arr[0][1] == '0' && arr[1][1] == '0' && arr[2][1] == '0') ||
           (arr[0][2] == '0' && arr[1][2] == '0' && arr[2][2] == '0'))
    return 2;
  else
    return 0;
}
bool winner1(char arr[3][3]) {
  if ((arr[0][0] == 'X' && arr[0][1] == 'X' && arr[0][2] == 'X') ||
      (arr[1][0] == 'X' && arr[1][1] == 'X' && arr[1][2] == 'X') ||
      (arr[2][0] == 'X' && arr[2][1] == 'X' && arr[2][2] == 'X') ||
      (arr[0][0] == 'X' && arr[1][1] == 'X' && arr[2][2] == 'X') ||
      (arr[0][2] == 'X' && arr[1][1] == 'X' && arr[2][0] == 'X') ||
      (arr[0][0] == 'X' && arr[1][0] == 'X' && arr[2][0] == 'X') ||
      (arr[0][1] == 'X' && arr[1][1] == 'X' && arr[2][1] == 'X') ||
      (arr[0][2] == 'X' && arr[1][2] == 'X' && arr[2][2] == 'X'))
    return 1;
  return 0;
}
bool winner2(char arr[3][3]) {
  if ((arr[0][0] == '0' && arr[0][1] == '0' && arr[0][2] == '0') ||
      (arr[1][0] == '0' && arr[1][1] == '0' && arr[1][2] == '0') ||
      (arr[2][0] == '0' && arr[2][1] == '0' && arr[2][2] == '0') ||
      (arr[0][0] == '0' && arr[1][1] == '0' && arr[2][2] == '0') ||
      (arr[0][2] == '0' && arr[1][1] == '0' && arr[2][0] == '0') ||
      (arr[0][0] == '0' && arr[1][0] == '0' && arr[2][0] == '0') ||
      (arr[0][1] == '0' && arr[1][1] == '0' && arr[2][1] == '0') ||
      (arr[0][2] == '0' && arr[1][2] == '0' && arr[2][2] == '0'))
    return 1;
  return 0;
}
int main() {
  char ar[3][3];
  int x = 0, o = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> ar[i][j];
      if (ar[i][j] == 'X')
        x++;
      else if (ar[i][j] == '0')
        o++;
    }
  }
  int w = winner(ar);
  bool one = winner1(ar), two = winner2(ar);
  if ((o > x) || (abs(x - o) > 1) || (one && two) || (one && o == x) ||
      (two && x > o))
    cout << "illegal" << endl;
  else if (!w && (x == 5 && o == 4))
    cout << "draw" << endl;
  else if (w == 1)
    cout << "the first player won" << endl;
  else if (w == 2)
    cout << "the second player won" << endl;
  else {
    if (x > o)
      cout << "second" << endl;
    else if (x == o)
      cout << "first" << endl;
  }
  return 0;
}
