#include <bits/stdc++.h>
using namespace std;
const int maxn = 1E6 + 5;
int main() {
  string str[4];
  int T = 0, q = 0, w = 0;
  int a[10] = {0};
  cin >> str[1] >> str[2] >> str[3];
  for (int i = 1; i <= 3; i++)
    for (int j = 0; j < 3; j++) {
      if (str[i][j] == '.') T = 1;
      if (str[i][j] == 'X') q++;
      if (str[i][j] == '0') w++;
    }
  if (q != w && q != w + 1) a[1] = 1;
  if (str[1][0] == 'X' && str[2][1] == 'X' && str[3][2] == 'X') a[2] = 1;
  if (str[1][1] == 'X' && str[2][1] == 'X' && str[3][1] == 'X') a[2] = 1;
  if (str[1][2] == 'X' && str[2][1] == 'X' && str[3][0] == 'X') a[2] = 1;
  if (str[1][0] == 'X' && str[2][0] == 'X' && str[3][0] == 'X') a[2] = 1;
  if (str[1][2] == 'X' && str[2][2] == 'X' && str[3][2] == 'X') a[2] = 1;
  if (str[1][1] == 'X' && str[1][0] == 'X' && str[1][2] == 'X') a[2] = 1;
  if (str[2][1] == 'X' && str[2][0] == 'X' && str[2][2] == 'X') a[2] = 1;
  if (str[3][1] == 'X' && str[3][0] == 'X' && str[3][2] == 'X') a[2] = 1;
  if (str[1][0] == '0' && str[2][1] == '0' && str[3][2] == '0') a[3] = 1;
  if (str[1][1] == '0' && str[2][1] == '0' && str[3][1] == '0') a[3] = 1;
  if (str[1][2] == '0' && str[2][1] == '0' && str[3][0] == '0') a[3] = 1;
  if (str[1][0] == '0' && str[2][0] == '0' && str[3][0] == '0') a[3] = 1;
  if (str[1][2] == '0' && str[2][2] == '0' && str[3][2] == '0') a[3] = 1;
  if (str[1][1] == '0' && str[1][0] == '0' && str[1][2] == '0') a[3] = 1;
  if (str[2][1] == '0' && str[2][0] == '0' && str[2][2] == '0') a[3] = 1;
  if (str[3][1] == '0' && str[3][0] == '0' && str[3][2] == '0') a[3] = 1;
  if (!T && (q == w || q == w + 1)) a[4] = 1;
  if (q == w) a[5] = 1;
  if (q == w + 1) a[6] = 1;
  if (a[1] || (a[2] && a[3]))
    cout << "illegal" << endl;
  else if ((a[2] && q == w) || (a[3] && q == w + 1))
    cout << "illegal" << endl;
  else if (a[2] && !a[3])
    cout << "the first player won" << endl;
  else if (a[3] && !a[2])
    cout << "the second player won" << endl;
  else if (!T && q == w + 1 && !a[2] && !a[3])
    cout << "draw" << endl;
  else if (!a[2] && !a[3] && q == w)
    cout << "first" << endl;
  else if (!a[2] && !a[3] && q == w + 1)
    cout << "second" << endl;
}
