import java.util.Scanner;
public class WZQ
{
    
static char[] xy = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o'};
    
public static void main(String[] args)
    
{
        WZQ a 
= new WZQ();
        Scanner sca 
= new Scanner(System.in);
        
int i,j;
        String str
="";
        
char[][] qp = new char[xy.length][xy.length];
        
for(i=0 ; i<xy.length ; i++)
        
{
            
for(j=0 ; j<xy.length ;j++)
            
{
                qp[i][j] 
= '';//构成棋盘
            }

        }

    
//    a.output(qp);
        for(i=0;;i++)//黑子为○,应为反白显示
        {
            a.output(qp);
            
int x,y;//分别输入横从坐标
            System.out.println((i%2==0)?"黑方走:":"白方走:");
            
            str 
= sca.next();//如果为exit推出
            if(str.equals("exit"))
                
return;
                
            x 
= str.charAt(0)-97;
            y 
= sca.next().charAt(0)-97;
                
            
if(x<0 || x>14 || y<0 || y>14 )
            
{
                System.out.println(
"输入错误");
                i
--;
                
continue;
            }

            
if(i%2==0)
            
{
            
//    System.out.println("黑方走:");
                
                
if(qp[x][y]=='')
                
{
                    qp 
= a.walk(qp,x,y,'');
                }

                
else
                
{
                    System.out.println(
"输入错误");
                    i
--;
                    
continue;
                }

                
                
if(a.iswin(qp,x,y,''))
                
{
                    a.output(qp);
                    System.out.println(
"黑方获胜");
                    
break;
                }

            }

            
else
            
{
            
//    System.out.println("白方走:");
                
                
if(qp[x][y]=='')
                
{
                    qp 
= a.walk(qp,x,y,'');
                }

                
else
                
{
                    System.out.println(
"输入错误");
                    i
--;
                    
continue;
                }

                
                a.walk(qp,x,y,
'');
                
if(a.iswin(qp,x,y,''))
                
{
                    a.output(qp);
                    System.out.println(
"白方获胜");
                    
break;
                }

            }
    
        }

        
    }

    
    
void output(char[][] out)
    
{
        
int i,j;
        String str 
= "  ";
        
for(i=0 ; i<xy.length ; i++)
            str 
+= xy[i]+" ";
        str 
+= "\n";
        
for(i=0 ; i<xy.length ; i++)
        
{
            str 
+= xy[i];
            
for(j=0 ; j<xy.length ;j++)
            str 
+= out[i][j];
            str 
+= "\n";
        }

        
        System.out.print(str);
    }

    
    
char[][] walk(char[][] walk,int i,int j,char mark)
    
{
        walk[i][j] 
= mark;
        
return walk;
    }

    
    
boolean iswin(char[][] walk,int i,int j,char mark)//从8个方向上判断是否有五子连珠
    {
        
int x,y;
        
int num=0;//计数为5时胜利
        
//开始判断方向\ 一直搜索到头然后往返(一下方法相同)
        x = i;
        y 
= j;
        
        
while(x>=0 && y>=0)
        
{
            
if(walk[x][y]==mark)
            
{
                num
++;
                x
--;
                y
--;
            }

            
else
            
{
                
break;
            }
        
            
if(num==5){
                
return true;
            }

        }

        
        x
=i+1;
        y
=j+1;
            
        
while(x<15 && y<15)
        
{
            
if(walk[x][y]==mark)
            
{
                num
++;
                x
++;
                y
++;    
            }

            
else
            
{
                
break;
            }
        
            
if(num==5){
                
return true;
            }

        }
//结束
        
        
//开始判断方向- 一直搜索到头x不变
        x = i;
        y 
= j;
        num 
= 0;
        
while(y>=0)
        
{
            
if(walk[x][y]==mark)
            
{
                num
++;
                y
--;
            }

            
else
            
{
                
break;
            }
        
            
if(num==5){
                
return true;
            }

        }

        
        y
=j+1;
        
        
while(y<15)
        
{
            
if(walk[x][y]==mark)
            
{
                num
++;
                y
++;    
            }

            
else
            
{
                
break;
            }
        
            
if(num==5){
                
return true;
            }

        }

        
//结束
        
        
//开始判断方向/ 一直搜索到头
        x = i;
        y 
= j;
        num 
= 0;
        
while(x>=0 && y<15)
        
{
            
if(walk[x][y]==mark)
            
{
                num
++;
                x
--;
                y
++;
            }

            
else
            
{
                
                
break;
            }
        
            
if(num==5){
                
return true;
            }

        }

        
        x
=i+1;
        y
=j-1;
            
        
while(x<15 && y>=0)
        
{
            
if(walk[x][y]==mark)
            
{
                num
++
                x
++;
                y
--;    
            }

            
else
            
{
                
break;
            }
        
            
if(num==5){
                
return true;
            }

        }

        
//结束
        
        
//开始判断方向| 一直搜索到头y不变
        x = i;
        y 
= j;
        num 
= 0;
        
while(x>=0)
        
{
            
if(walk[x][y]==mark)
            
{
                num
++;
                x
--;
            }

            
else
            
{
                
                
break;
            }
        
            
if(num==5){
                
return true;
            }

        }

            
        x
=i+1;
        
        
while(x<15)
        
{
            
if(walk[x][y]==mark)
            
{
                num
++;
                x
++;
            }

            
else
            
{
                
break;
            }
        
            
if(num==5){
                
return true;
            }

        }

        
//结束
        return false;
    }

}