#include <bits/stdc++.h>
using namespace std;
char a[3][3];
int counterX = 0, counterO = 0;
int x = 0, m = 0, y = 0;
int victoryX = 0, victoryO = 0;
void input() {
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) cin >> a[i][j];
}
void illegal() {
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      if (a[i][j] == 'X')
        counterX++;
      else if (a[i][j] == '0')
        counterO++;
    }
  if (counterX - counterO == 1 || counterX - counterO == 0)
    ;
  else {
    x = 1;
    cout << "illegal";
    return;
  }
}
void finish() {
  for (int i = 0; i < 3; i++) {
    if (a[i][0] == 'X' && a[i][1] == 'X' && a[i][2] == 'X') {
      victoryX = 1;
    }
    if (a[i][0] == '0' && a[i][1] == '0' && a[i][2] == '0') {
      victoryO = 1;
    }
  }
  for (int j = 0; j < 3; j++) {
    if (a[0][j] == 'X' && a[1][j] == 'X' && a[2][j] == 'X') {
      victoryX = 1;
    }
    if (a[0][j] == '0' && a[1][j] == '0' && a[2][j] == '0') {
      victoryO = 1;
    }
  }
  if (a[0][0] == 'X' && a[1][1] == 'X' && a[2][2] == 'X') {
    victoryX = 1;
  }
  if (a[0][0] == '0' && a[1][1] == '0' && a[2][2] == '0') {
    victoryO = 1;
  }
  if (a[0][2] == 'X' && a[1][1] == 'X' && a[2][0] == 'X') {
    victoryX = 1;
  }
  if (a[0][2] == '0' && a[1][1] == '0' && a[2][0] == '0') {
    victoryO = 1;
  }
  if (victoryO == 0 && victoryX == 0) {
    cout << "draw";
    return;
  }
  if (victoryO == 0 && victoryX == 1 && counterX == counterO + 1) {
    cout << "the first player won";
    return;
  }
  if (victoryO == 1 && victoryX == 0 && counterX == counterO) {
    cout << "the second player won";
    return;
  }
  cout << "illegal";
  y = 1;
}
void finish2() {
  for (int i = 0; i < 3; i++) {
    if (a[i][0] == 'X' && a[i][1] == 'X' && a[i][2] == 'X') {
      victoryX = 1;
    }
    if (a[i][0] == '0' && a[i][1] == '0' && a[i][2] == '0') {
      victoryO = 1;
    }
  }
  for (int j = 0; j < 3; j++) {
    if (a[0][j] == 'X' && a[1][j] == 'X' && a[2][j] == 'X') {
      victoryX = 1;
    }
    if (a[0][j] == '0' && a[1][j] == '0' && a[2][j] == '0') {
      victoryO = 1;
    }
  }
  if (a[0][0] == 'X' && a[1][1] == 'X' && a[2][2] == 'X') {
    victoryX = 1;
  }
  if (a[0][0] == '0' && a[1][1] == '0' && a[2][2] == '0') {
    victoryO = 1;
  }
  if (a[0][2] == 'X' && a[1][1] == 'X' && a[2][0] == 'X') {
    victoryX = 1;
  }
  if (a[0][2] == '0' && a[1][1] == '0' && a[2][0] == '0') {
    victoryO = 1;
  }
  if (victoryO == 0 && victoryX == 0) {
    return;
  }
  if (victoryO == 0 && victoryX == 1 && counterX == counterO + 1) {
    cout << "the first player won";
    m = 1;
    return;
  }
  if (victoryO == 1 && victoryX == 0 && counterX == counterO) {
    cout << "the second player won";
    m = 1;
    return;
  }
  cout << "illegal";
  y = 1;
}
int main() {
  input();
  illegal();
  if (x == 0) {
    if (counterX + counterO == 9)
      finish();
    else {
      finish2();
      if (m == 0 && x == 0 && y == 0) {
        if (counterO == counterX)
          cout << "first";
        else
          cout << "second";
      }
    }
  }
}
