#include <bits/stdc++.h>
using namespace std;
struct pos {
  int a[3][3];
  pos() { memset(a, 0, sizeof(a)); };
  int in_binaray() {
    int res = 0, cur = 0;
    for (int i = 0; i < 3; ++i)
      for (int j = 0; j < 3; ++j) {
        res ^= (a[i][j] << (2 * cur));
        ++cur;
      }
    return res;
  }
  int winner() {
    for (int i = 0; i < 3; ++i) {
      if (!a[i][0]) continue;
      bool eq = 1;
      for (int j = 0; j < 3; ++j)
        if (a[i][j] != a[i][0]) eq = 0;
      if (eq) return a[i][0];
    }
    for (int i = 0; i < 3; i++) {
      if (!a[0][i]) continue;
      bool eq = 1;
      for (int j = 0; j < 3; j++)
        if (a[j][i] != a[0][i]) eq = 0;
      if (eq) return a[0][i];
    }
    if (a[0][0] == a[1][1] && a[1][1] == a[2][2]) return a[0][0];
    if (a[0][2] == a[1][1] && a[1][1] == a[2][0]) return a[0][2];
    return 0;
  }
  bool draw() {
    int c = 0;
    for (int i = 0; i < 3; ++i)
      for (int j = 0; j < 3; ++j)
        if (!a[i][j]) c++;
    return (c == 0);
  }
  int who() {
    int b = 0;
    for (int i = 0; i < 3; ++i)
      for (int j = 0; j < 3; ++j)
        if (a[i][j] == 1)
          b++;
        else if (a[i][j] == 2)
          b--;
    return (b == 0 ? 1 : 2);
  }
};
set<int> fi, se, fiw, sew, dr;
void dfs(pos p) {
  int x = p.in_binaray();
  int w = p.winner();
  if (w) {
    if (w == 1)
      fiw.insert(x);
    else
      sew.insert(x);
    return;
  }
  if (p.draw()) {
    dr.insert(x);
    return;
  }
  int who = p.who();
  if (who == 1)
    fi.insert(x);
  else
    se.insert(x);
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      if (p.a[i][j]) continue;
      p.a[i][j] = who;
      dfs(p);
      p.a[i][j] = 0;
    }
}
int main() {
  pos p;
  dfs(p);
  pos q;
  for (int i = 0; i < 3; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < 3; j++) {
      if (s[j] == 'X')
        q.a[i][j] = 1;
      else if (s[j] == '0')
        q.a[i][j] = 2;
      else
        q.a[i][j] = 0;
    }
  }
  int x = q.in_binaray();
  if (fi.count(x))
    puts("first");
  else if (se.count(x))
    puts("second");
  else if (fiw.count(x))
    puts("the first player won");
  else if (sew.count(x))
    puts("the second player won");
  else if (dr.count(x))
    puts("draw");
  else
    puts("illegal");
  return 0;
}
