#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  ifstream from;
  const long long nmin = 1, nmax = 100;
  long long n, m, res, rt, i, i0, j, j0, k, ax, bx, nx, no;
  char ch;
  string sres[6] = {"illegal",
                    "first",
                    "second",
                    "the first player won",
                    "the second player won",
                    "draw"};
  if (0) from.open("test.txt");
  vector<vector<char> > v(3);
  for (i = 0; i < 3; i++) v[i].resize(3);
  res = nx = no = 0;
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      cin >> ch;
      v[i][j] = ch;
      if (ch == 'X')
        nx++;
      else if (ch == '0')
        no++;
    }
  }
  if (nx == no + 1) {
    if (nx == 1)
      res = 2;
    else {
      ch = 'X';
      ax = 0;
      for (i0 = 0; (i0 < 3) && (ax == 0); i0++) {
        for (j0 = 0; (j0 < 3) && (ax == 0); j0++) {
          if (v[i0][j0] == ch) {
            ax = 1;
            v[i0][j0] = '.';
            for (i = 0; i < 3; i++) {
              if ((v[i][0] == v[i][1]) && (v[i][1] == v[i][2]) &&
                  (v[i][2] != '.'))
                ax = 0;
              if ((v[0][i] == v[1][i]) && (v[1][i] == v[2][i]) &&
                  (v[2][i] != '.'))
                ax = 0;
            }
            if ((v[0][0] == v[1][1]) && (v[1][1] == v[2][2]) &&
                (v[2][2] != '.'))
              ax = 0;
            if ((v[0][2] == v[1][1]) && (v[1][1] == v[2][0]) &&
                (v[2][0] != '.'))
              ax = 0;
            v[i0][j0] = ch;
          }
        }
      }
      if (ax == 0)
        res = 0;
      else {
        ax = 1;
        for (i = 0; i < 3; i++) {
          if ((v[i][0] == v[i][1]) && (v[i][1] == v[i][2]) && (v[i][2] != '.'))
            ax = 0;
          if ((v[0][i] == v[1][i]) && (v[1][i] == v[2][i]) && (v[2][i] != '.'))
            ax = 0;
        }
        if ((v[0][0] == v[1][1]) && (v[1][1] == v[2][2]) && (v[2][2] != '.'))
          ax = 0;
        if ((v[0][2] == v[1][1]) && (v[1][1] == v[2][0]) && (v[2][0] != '.'))
          ax = 0;
        if (ax == 0)
          res = 3;
        else if (nx == 5)
          res = 5;
        else
          res = 2;
      }
    }
  } else if (nx == no) {
    if (nx == 0)
      res = 1;
    else {
      ch = '0';
      ax = 0;
      for (i0 = 0; (i0 < 3) && (ax == 0); i0++) {
        for (j0 = 0; (j0 < 3) && (ax == 0); j0++) {
          if (v[i0][j0] == ch) {
            ax = 1;
            v[i0][j0] = '.';
            for (i = 0; i < 3; i++) {
              if ((v[i][0] == v[i][1]) && (v[i][1] == v[i][2]) &&
                  (v[i][2] != '.'))
                ax = 0;
              if ((v[0][i] == v[1][i]) && (v[1][i] == v[2][i]) &&
                  (v[2][i] != '.'))
                ax = 0;
            }
            if ((v[0][0] == v[1][1]) && (v[1][1] == v[2][2]) &&
                (v[2][2] != '.'))
              ax = 0;
            if ((v[0][2] == v[1][1]) && (v[1][1] == v[2][0]) &&
                (v[2][0] != '.'))
              ax = 0;
            v[i0][j0] = ch;
          }
        }
      }
      if (ax == 0)
        res = 0;
      else {
        ax = 1;
        for (i = 0; i < 3; i++) {
          if ((v[i][0] == v[i][1]) && (v[i][1] == v[i][2]) && (v[i][2] != '.'))
            ax = 0;
          if ((v[0][i] == v[1][i]) && (v[1][i] == v[2][i]) && (v[2][i] != '.'))
            ax = 0;
        }
        if ((v[0][0] == v[1][1]) && (v[1][1] == v[2][2]) && (v[2][2] != '.'))
          ax = 0;
        if ((v[0][2] == v[1][1]) && (v[1][1] == v[2][0]) && (v[2][0] != '.'))
          ax = 0;
        if (ax == 0)
          res = 4;
        else
          res = 1;
      }
    }
  }
  cout << sres[res] << endl;
  return 0;
}
