#include <bits/stdc++.h>
using namespace std;
int main() {
  char grid[3][3];
  int x = 0, o = 0, p = 0, flagr = 0, flagc = 0, flago = 0, flagx = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> grid[i][j];
      switch (grid[i][j]) {
        case 'X':
          ++x;
          break;
        case '0':
          ++o;
          break;
        case '.':
          ++p;
      }
    }
  }
  if (x - o > 1 || x - o < 0) {
    cout << "illegal" << endl;
    return 0;
  }
  for (int i = 0; i < 3; i++) {
    if (grid[i][0] == grid[i][1] && grid[i][1] == grid[i][2]) {
      switch (grid[i][0]) {
        case 'X':
          flagx = 1;
          flagr++;
          break;
        case '0':
          flago = 1;
          flagr++;
      }
    }
    if (grid[0][i] == grid[1][i] && grid[1][i] == grid[2][i]) {
      switch (grid[0][i]) {
        case 'X':
          flagx = 1;
          flagc++;
          break;
        case '0':
          flago = 1;
          flagc++;
      }
    }
  }
  if ((grid[0][0] == grid[1][1] && grid[1][1] == grid[2][2]) ||
      (grid[0][2] == grid[1][1] && grid[1][1] == grid[2][0])) {
    switch (grid[1][1]) {
      case 'X':
        flagx = 1;
        break;
      case '0':
        flago = 1;
    }
  }
  if (flagr > 1 || flagc > 1 || (flagx && x == o) || (flago && x == o + 1))
    cout << "illegal" << endl;
  else if (flagx && x == o + 1)
    cout << "the first player won" << endl;
  else if (flago && x == o)
    cout << "the second player won" << endl;
  else if (p == 0)
    cout << "draw" << endl;
  else {
    if (x == o)
      cout << "first" << endl;
    else
      cout << "second" << endl;
  }
  return 0;
}
