#include <bits/stdc++.h>
using namespace std;
char p[3][3];
int a=0,b=0,c=0;
void check_win()
{
if(p[0][0]=='X'&&p[0][1]=='X'&&p[0][2]=='X'){printf("the first player won");exit(0);}
if(p[1][0]=='X'&&p[1][1]=='X'&&p[1][2]=='X'){printf("the first player won");exit(0);}
if(p[2][0]=='X'&&p[2][1]=='X'&&p[2][2]=='X'){printf("the first player won");exit(0);}
if(p[0][0]=='X'&&p[1][0]=='X'&&p[2][0]=='X'){printf("the first player won");exit(0);}
if(p[0][1]=='X'&&p[1][1]=='X'&&p[2][1]=='X'){printf("the first player won");exit(0);}
if(p[0][2]=='X'&&p[1][2]=='X'&&p[2][2]=='X'){printf("the first player won");exit(0);}
if(p[0][0]=='X'&&p[1][1]=='X'&&p[2][2]=='X'){printf("the first player won");exit(0);}
if(p[0][2]=='X'&&p[1][1]=='X'&&p[2][0]=='X'){printf("the first player won");exit(0);}
if(p[0][0]=='0'&&p[0][1]=='0'&&p[0][2]=='0'){printf("the second player won");exit(0);}
if(p[1][0]=='0'&&p[1][1]=='0'&&p[1][2]=='0'){printf("the second player won");exit(0);}
if(p[2][0]=='0'&&p[2][1]=='0'&&p[2][2]=='0'){printf("the second player won");exit(0);}
if(p[0][0]=='0'&&p[1][0]=='0'&&p[2][0]=='0'){printf("the second player won");exit(0);}
if(p[0][1]=='0'&&p[1][1]=='0'&&p[2][1]=='0'){printf("the second player won");exit(0);}
if(p[0][2]=='0'&&p[1][2]=='0'&&p[2][2]=='0'){printf("the second player won");exit(0);}
if(p[0][0]=='0'&&p[1][1]=='0'&&p[2][2]=='0'){printf("the second player won");exit(0);}
if(p[0][2]=='0'&&p[1][1]=='0'&&p[2][0]=='0'){printf("the second player won");exit(0);}
}
void check_go()
{
if(a>b){printf("second");exit(0);}
if(a==b){printf("first");exit(0);}
}
void check_no()
{
if(abs(a-b)>1||b>a){printf("illegal");exit(0);}
}
int main()
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
{
cin>>p[i][j];
if(p[i][j]=='X') a++;
if(p[i][j]=='0') b++;
if(p[i][j]=='.') c++;
}
check_win();
check_go();
check_no();
printf("draw");
return 0;
}