#include <bits/stdc++.h>
using namespace std;
int main() {
  int cross = 0;
  int circle = 0;
  char arr[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == 'X')
        cross++;
      else if (arr[i][j] == '0')
        circle++;
    }
  }
  int win_cross = 0;
  int win_circle = 0;
  for (int i = 0; i < 3; i++) {
    int a = 0;
    int b = 0;
    for (int j = 0; j < 3; j++) {
      if (arr[i][j] == 'X')
        a++;
      else if (arr[i][j] == '0')
        b++;
    }
    if (a == 3) win_cross++;
    if (b == 3) win_circle++;
  }
  for (int j = 0; j < 3; j++) {
    int a = 0;
    int b = 0;
    for (int i = 0; i < 3; i++) {
      if (arr[i][j] == 'X')
        a++;
      else if (arr[i][j] == '0')
        b++;
    }
    if (a == 3) win_cross++;
    if (b == 3) win_circle++;
  }
  if (arr[0][0] == 'X' && arr[1][1] == 'X' && arr[2][2] == 'X') win_cross++;
  if (arr[0][2] == 'X' && arr[1][1] == 'X' && arr[2][0] == 'X') win_cross++;
  if (arr[0][0] == '0' && arr[1][1] == '0' && arr[2][2] == '0') win_circle++;
  if (arr[0][2] == '0' && arr[1][1] == '0' && arr[2][0] == '0') win_circle++;
  if (win_cross == 0 && win_circle == 0) {
    if (cross == 5 && circle == 4)
      cout << "draw" << endl;
    else if (cross - circle == 0)
      cout << "first" << endl;
    else if (cross - circle == 1)
      cout << "second" << endl;
    else
      cout << "illegal" << endl;
  } else if (win_cross == 0 && win_circle >= 1 && cross == circle)
    cout << "the second player won" << endl;
  else if (win_cross >= 1 && win_circle == 0 && cross == circle + 1)
    cout << "the first player won" << endl;
  else
    cout << "illegal" << endl;
  return 0;
}
