#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:100000000")
string s[3];
int main() {
  cin >> s[0] >> s[1] >> s[2];
  int cnt1 = 0;
  int cnt2 = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (s[i][j] == 'X') cnt1++;
      if (s[i][j] == '0') cnt2++;
    }
  }
  bool win1 = false;
  bool win2 = false;
  for (int i = 0; i < 3; i++) {
    if (s[i] == "XXX") win1 = true;
    if (s[i] == "000") win2 = true;
  }
  for (int i = 0; i < 3; i++) {
    if (s[0][i] == 'X' && s[1][i] == 'X' && s[2][i] == 'X') win1 = true;
    if (s[0][i] == '0' && s[1][i] == '0' && s[2][i] == '0') win2 = true;
  }
  if (s[0][0] == 'X' && s[1][1] == 'X' && s[2][2] == 'X') win1 = true;
  if (s[0][2] == 'X' && s[1][1] == 'X' && s[2][0] == 'X') win1 = true;
  if (s[0][0] == '0' && s[1][1] == '0' && s[2][2] == '0') win2 = true;
  if (s[0][2] == '0' && s[1][1] == '0' && s[2][0] == '0') win2 = true;
  if (win1 && win2 || win1 && cnt1 == cnt2 || win2 && cnt1 != cnt2 ||
      abs(cnt1 - cnt2) > 1 || cnt2 > cnt1)
    cout << "illegal" << endl;
  else if (win1)
    cout << "the first player won" << endl;
  else if (win2)
    cout << "the second player won" << endl;
  else if (cnt1 + cnt2 == 9)
    cout << "draw" << endl;
  else if (cnt1 == cnt2)
    cout << "first" << endl;
  else
    cout << "second" << endl;
  return 0;
}
