#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int mod0 = 1e9 + 7;
const long long mod1 = 998244353;
const long long mod2 = 1e9 + 9;
const long long mod3 = 2147483647;
const int sz = 1024 * 1024;
const long long inf = 2 * 1024 * 1024 * 1023 - 1;
const long long INF = inf * inf;
const double eps = 1e-6;
void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(16);
}
const int N = 2e5 + 2;
void solve() {
  vector<string> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];
  int cntx = 0, cnt0 = 0;
  vector<int> cntr1(3), cntc1(3);
  vector<int> cntr2(3), cntc2(3);
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cntx += (a[i][j] == 'X');
      cnt0 += (a[i][j] == '0');
      if (a[i][j] == 'X') {
        cntr1[i]++, cntc1[j]++;
      }
      if (a[i][j] == '0') {
        cntr2[i]++, cntc2[j]++;
      }
    }
  }
  if (cnt0 > cntx || cntx > cnt0 + 1) {
    cout << "illegal\n";
    return;
  }
  int cntw1 = 0, cntw2 = 0;
  for (int i = 0; i < 3; ++i) {
    cntw1 += (cntr1[i] == 3);
    cntw1 += (cntc1[i] == 3);
    cntw2 += (cntr2[i] == 3);
    cntw2 += (cntc2[i] == 3);
  }
  cntw1 += (a[0][0] == 'X' && a[1][1] == 'X' && a[2][2] == 'X');
  cntw1 += (a[2][0] == 'X' && a[1][1] == 'X' && a[0][2] == 'X');
  cntw2 += (a[0][0] == '0' && a[1][1] == '0' && a[2][2] == '0');
  cntw2 += (a[2][0] == '0' && a[1][1] == '0' && a[0][2] == '0');
  if (cntw1 + cntw2 > 1) {
    if (cntw1 == 2 && cntw2 == 0) {
      if (cntx == 5 && cntx == cnt0 + 1) {
        cout << "the first player won\n";
        return;
      }
    }
    cout << "illegal\n";
    return;
  }
  if (cntw1 == 1) {
    if (cntx != cnt0 + 1) {
      cout << "illegal\n";
      return;
    }
    cout << "the first player won\n";
    return;
  }
  if (cntw2 == 1) {
    if (cntx != cnt0) {
      cout << "illegal\n";
      return;
    }
    cout << "the second player won\n";
    return;
  }
  if (cntx + cnt0 == 9) {
    cout << "draw\n";
    return;
  }
  cout << (cntx == cnt0 ? "first" : "second") << '\n';
}
bool multitest = false;
int main() {
  init();
  int t = 1;
  if (multitest) cin >> t;
  for (int i = 0; i < t; ++i) solve();
  return 0;
}
