#include <bits/stdc++.h>
using namespace std;
char a[4][5];
int num1, num2;
int check() {
  int ans = 0;
  for (int i = 1; i <= 3; i++)
    if (a[i][0] == a[i][1] && a[i][1] == a[i][2])
      if (a[i][0] == 'X')
        ans++;
      else if (a[i][0] == '0')
        ans++;
  if (ans > 1) return 2;
  if (ans == 0)
    for (int i = 0; i < 3; i++)
      if (a[1][i] == a[2][i] && a[2][i] == a[3][i])
        if (a[1][i] == 'X')
          ans++;
        else if (a[1][i] == '0')
          ans++;
  if (ans == 0)
    if (a[1][0] == a[2][1] && a[2][1] == a[3][2])
      if (a[1][0] == 'X')
        ans++;
      else if (a[1][0] == '0')
        ans++;
      else if (a[1][2] == a[2][1] && a[2][1] == a[3][0])
        if (a[1][2] == 'X')
          ans++;
        else if (a[1][2] == '0')
          ans++;
  if (ans > 0) return 1;
  return 1;
}
int main() {
  for (int i = 1; i <= 3; i++) cin >> a[i];
  for (int i = 1; i <= 3; i++)
    for (int j = 0; j < 3; j++)
      if (a[i][j] == '0')
        num2++;
      else if (a[i][j] == 'X')
        num1++;
  if (num2 > num1 || num1 - num2 > 1) {
    puts("illegal");
    return 0;
  }
  int ans = check();
  if (ans > 1) {
    puts("illegal");
    return 0;
  }
  if (ans == 1) {
    for (int i = 1; i <= 3; i++)
      if (a[i][0] == a[i][1] && a[i][1] == a[i][2])
        if (a[i][0] == 'X') {
          if (num1 == num2) {
            puts("illegal");
            return 0;
          }
          puts("the first player won");
          return 0;
        } else if (a[i][0] == '0') {
          if (num1 > num2) {
            puts("illegal");
            return 0;
          }
          puts("the second player won");
          return 0;
        }
    for (int i = 0; i < 3; i++)
      if (a[1][i] == a[2][i] && a[2][i] == a[3][i])
        if (a[1][i] == 'X') {
          if (num1 == num2) {
            puts("illegal");
            return 0;
          }
          puts("the first player won");
          return 0;
        } else if (a[1][i] == '0') {
          if (num1 > num2) {
            puts("illegal");
            return 0;
          }
          puts("the second player won");
          return 0;
        }
    if (a[1][0] == a[2][1] && a[2][1] == a[3][2])
      if (a[1][0] == 'X') {
        if (num1 == num2) {
          puts("illegal");
          return 0;
        }
        puts("the first player won");
        return 0;
      } else if (a[1][0] == '0') {
        if (num1 > num2) {
          puts("illegal");
          return 0;
        }
        puts("the second player won");
        return 0;
      }
    if (a[1][2] == a[2][1] && a[2][1] == a[3][0])
      if (a[1][2] == 'X') {
        if (num1 == num2) {
          puts("illegal");
          return 0;
        }
        puts("the first player won");
        return 0;
      } else if (a[1][2] == '0') {
        if (num1 > num2) {
          puts("illegal");
          return 0;
        }
        puts("the second player won");
        return 0;
      }
  }
  if (num1 == 5 && num2 == 4) {
    puts("draw");
    return 0;
  }
  if (num1 > num2)
    puts("second");
  else
    puts("first");
  return 0;
}
