#include <bits/stdc++.h>
using namespace std;
string grid = ".........";
map<string, string> ans;
bool win(string s, char c) {
  for (int i = 0; i < 3; i++) {
    if (s[3 * i] == c and s[3 * i + 1] == c and s[3 * i + 2] == c) return 1;
    if (s[i] == c and s[i + 3] == c and s[i + 6] == c) return 1;
  }
  if (s[0] == c and s[4] == c and s[8] == c) return 1;
  if (s[2] == c and s[4] == c and s[6] == c) return 1;
  return 0;
}
void search(int t) {
  if (win(grid, 'X')) {
    ans[grid] = "the first player won";
    return;
  }
  if (win(grid, '0')) {
    ans[grid] = "the second player won";
    return;
  }
  if (t == 9) {
    ans[grid] = "draw";
    return;
  }
  if (t % 2 == 0)
    ans[grid] = "first";
  else
    ans[grid] = "second";
  for (int i = 0; i < 9; i++)
    if (grid[i] == '.') {
      grid[i] = t % 2 ? '0' : 'X';
      search(t + 1);
      grid[i] = '.';
    }
}
int main() {
  search(0);
  string s, t;
  for (int i = 0; i < 3; i++) {
    cin >> t;
    s += t;
  }
  if (ans.find(s) == ans.end())
    puts("illegal");
  else
    cout << ans[s] << '\n';
  return 0;
}
