#include <bits/stdc++.h>
using namespace std;
int a[5][5];
int p1 = 0, p2 = 0, k = 0;
bool f1, f2;
int main() {
  for (int i = 1; i <= 3; ++i) {
    for (int j = 1; j <= 3; ++j) {
      char s = getchar();
      if (s == 'X')
        a[i][j] = 1, p1++;
      else if (s == '0')
        a[i][j] = 2, p2++;
      else
        a[i][j] = 0, k++;
    }
    getchar();
  }
  if (p1 > p2 + 1 || p1 < p2) {
    puts("illegal");
    return 0;
  }
  for (int i = 1; i <= 3; ++i) {
    bool f = 0;
    for (int j = 2; j <= 3; ++j) {
      if (a[i][j] != a[i][j - 1]) {
        f = 1;
        break;
      }
    }
    if (!f) {
      if (a[i][1] == 1) {
        f1 = 1;
      } else if (a[i][1] == 2) {
        f2 = 1;
      }
    }
  }
  for (int j = 1; j <= 3; ++j) {
    bool f = 0;
    for (int i = 2; i <= 3; ++i) {
      if (a[i][j] != a[i - 1][j]) {
        f = 1;
        break;
      }
    }
    if (!f) {
      if (a[1][j] == 1) {
        f1 = 1;
      } else if (a[1][j] == 2) {
        f2 = 1;
      }
    }
  }
  for (int i = 2; i <= 3; ++i) {
    if (a[i][i] != a[i - 1][i - 1]) break;
    if (i == 3) {
      if (a[1][1] == 1) {
        f1 = 1;
      } else if (a[1][1] == 2) {
        f2 = 1;
      }
    }
  }
  for (int i = 2; i <= 3; ++i) {
    if (a[i - 1][3 - i + 2] != a[i][3 - i + 1]) break;
    if (i == 3) {
      if (a[1][3] == 1) {
        f1 = 1;
      } else if (a[1][3] == 2) {
        f2 = 2;
      }
    }
  }
  if (f1 && f2) {
    puts("illegal");
    return 0;
  } else if (f1 && p1 == p2 + 1) {
    puts("the first player won");
    return 0;
  } else if (f2 && p1 == p2) {
    puts("the second player won");
    return 0;
  } else if (f1 || f2) {
    puts("illegal");
    return 0;
  } else {
    if (k) {
      if (p1 == p2) {
        puts("first");
        return 0;
      } else {
        puts("second");
        return 0;
      }
    } else {
      puts("draw");
      return 0;
    }
  }
}
