Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».

This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed.  $8$ 

Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (r, c) the cell located at the row r and at the column c.

There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.

Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.

Moving upward means that the pawn located in (r, c) will go to the cell (r - 1, c), while moving down means the pawn located in (r, c) will go to the cell (r + 1, c). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.

Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.


-----Input-----

The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'. 

It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.


-----Output-----

Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.


-----Examples-----
Input
........
........
.B....B.
....W...
........
..W.....
........
........

Output
A

Input
..B.....
..W.....
......B.
........
.....W..
......B.
........
........

Output
B



-----Note-----

In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner.

Difficulty: interview

Starter code:

Solutions:
grid = [list(input()) for i in range(8)]
b = 9
w = 9
tblock = False
bblock = False
for r in range(8):
    for c in range(8):
        for ri in range(r):
            if grid[ri][c] == 'B':
                tblock = True
        for ri in range(r+1, 8):
            if grid[ri][c] == 'W':
                bblock = True
        if grid[r][c] == 'B' and not bblock:
            b = min([abs(7-r), b])
        elif grid[r][c] == 'W' and not tblock:
            w = min([w, r])
        tblock = False
        bblock = False
if b < w:
    print('B')
else:
    print('A')
        


z = []
for i in range(8):
    z.append(input())
a,b = 9,9
for i in range(8):
    for j in range(8):
        if z[i][j] == 'W':
            sedi = True
            for r in range(0, i):
                if z[r][j] == 'B':
                    sedi = False
                    break
            if sedi:
                a = min(a, i)
        elif z[i][j] == 'B':
            sedi = True
            for r in range(i+1, 8):
                if z[r][j] == 'W':
                    sedi = False
                    break
            if sedi:
                b = min(b, 7-i)
print('A' if a<=b else 'B')


our = [input() for i in range(8)]
resA = 100
resB = 100
for i in range(8):
    for j in range(8):
        if our[i][j] == 'W':
            curr = i
            while curr > 0 and our[curr - 1][j] == '.':
                curr -= 1
            if curr == 0:
                resA= min(resA, i)
        elif our[i][j] == 'B':
            curr = i
            while curr < 7 and our[curr + 1][j] == '.':
                curr += 1
            if curr == 7:
                resB = min(resB, curr - i)
if resA <= resB:
    print('A')
else:
    print('B')

s = [input().strip() for i in range(8)]

d1 = []
d2 = []

def check(x, y):
    if s[x][y] == 'B':
        for i in range(x + 1, 8):
            if s[i][y] == 'W':
                return False
    elif s[x][y] == 'W':
        for i in range(x - 1, -1, -1):
            if s[i][y] == 'B':
                return False
    return True

for i in range(8):
    for j in range(8):
        if s[i][j] == 'B' and check(i, j):
            d1.append(8 - i - 1)
        elif s[i][j] == 'W' and check(i, j):
            d2.append(i)


if min(d1) < min(d2):
    print("B")
else:
    print("A")


N = 8
a = [list(input()) for i in range(N)]
amin = N
bmin = N
for c in range(8):
    r = 0
    while r < N and a[r][c] == '.':
        r += 1
    if r < N and a[r][c] == 'W':
        amin = min(amin, r)
    r = N - 1
    while r >= 0 and a[r][c] == '.':
        r -= 1
    if r >= 0 and a[r][c] == 'B':
        bmin = min(bmin, N - 1 - r)
if amin <= bmin:
    print('A')
else:
    print('B')


p = []
for i in range(8):
    p.append(list(input()))
minb = 999999999
minch = 999999999
for i in range(8):
    for t in range(8):
        if p[i][t] == 'W':
            s = 0
            for e in range(i - 1, -1, -1):
                if p[e][t] != '.':
                    s = 999999
                else:
                    s += 1
            minb = min(minb, s)
        elif p[i][t] == 'B':
            s = 0
            for e in range(i + 1, 8):
                if p[e][t] != '.':
                    s = 999999
                else:
                    s += 1
            minch = min(minch, s)
if minb <= minch:
    print('A')
else:
    print('B')


field = [list(input()) for i in range(8)]
for y in range(8):
    for x in range(y + 1, 8):
        field[x][y], field[y][x] = field[y][x], field[x][y]

minW = 1000
minB = 1000
for row in range(8):
    w = None
    for col in range(7, -1, -1):
        if field[row][col] == "W":
            w = col
    if w != None and ("B" not in field[row][:w]):
        minW = min(minW, w)
    
    b = None
    for col in range(8):
        if field[row][col] == "B":
            b = col
    if b != None and ("W" not in field[row][b:]):
        minB = min(minB, 7 - b)
if minB < minW:
    print("B")
else:
    print("A")

import sys


#sys.stdin = open("input.txt")
#sys.stdout = open("output.txt", "w")

tbl = []
for i in range(8):
	tbl.append(input())

bestW = 10
bestB = 10
#print(tbl)

for i in range(8):
	for j in range(8):
		#print(i, j)
		if tbl[i][j] == 'W':
			ok = True
			for k in range(i):
				if tbl[k][j] != '.':
					ok = False
			if ok:
				bestW = min(bestW, i)
		elif tbl[i][j] == 'B':
			ok = True
			for k in range(8-i-1):
				if tbl[i + k + 1][j] != '.':
					ok = False
			if ok:
				bestB = min(bestB, 8 - i - 1)

#print(bestW, bestB)
if bestW <= bestB:
	print('A')
else:
	print('B')

#!/usr/bin/env python3

from sys import stdin

linecount = 8
field = []


def move_count(row, column, direction):
    if direction == 1:
        last = linecount
    else:
        last = -1

    count = 0

    for i in range(row + direction, last, direction):
        if field[i][c] != '.':
            return linecount
        else:
            count += 1

    return count



for i in range(0, linecount):
    field.append(list(stdin.readline().strip()))

a_moves = linecount
b_moves = linecount

for r in range(0, linecount):
    for c in range(0, linecount):
        if field[r][c] == 'W':
            count = move_count(r, c, -1)

            if count < a_moves:
                a_moves = count
        elif field[r][c] == 'B':
            count = move_count(r, c, 1)

            if count < b_moves:
                b_moves = count

if a_moves <= b_moves:
    print('A')
else:
    print('B')


A = [input() for i in range(8)]
B = 9
W = 9
for i in range(8):
    for j in range(8):
        if A[j][i] == "W":
            W = min(W, j)
            break
        if A[j][i] == "B":
            break
    for j in range(7, -1, -1):
        if A[j][i] == "B":
            B = min(B, 8 - j)
            break
        if A[j][i] =="W":
            break
if B <= W:
    print("B")
else:
    print("A")


def checkA(i, j):
    for k in range(i):
        if arr[k][j] != '.':
            return 1000
    return i

def checkB(i, j):
    for k in range(i + 1, 8):
        if arr[k][j] != '.':
            return 1000
    return 7 - i

#fin = open('a.in', 'r')
arr = []
for i in range(8):
    #a = fin.readline().strip()
    a = input()
    arr.append(a)
minA = 1000
minB = 1000
for i in range(8):
    for j in range(8):
        if arr[i][j] == 'W':
            minA = min(minA, checkA(i, j))
        if arr[i][j] == 'B':
            minB = min(minB, checkB(i, j))
if minA <= minB:
    print('A')
else:
    print('B')


white, black = [set() for _ in range(8)], [set() for _ in range(8)]
for row in range(8):
    for col, c in enumerate(input().strip()):
        if c == 'W':
            white[col].add(row)
        elif c == 'B':
            black[col].add(row)

min_w, max_b = 7, 0
for col in range(8):
    for w in white[col]:
        if all(b > w for b in black[col]) and w < min_w:
            min_w = w
    for b in black[col]:
        if all(b > w for w in white[col]) and b > max_b:
            max_b = b
#print(min_w, max_b)

if min_w <= 7 - max_b:
    print('A')
else:
    print('B')

import sys

#sys.stdin = open('input.txt')

top = [-1] * 8
top_let = [''] * 8
down = [-1] * 8
down_let = [''] * 8

for i in range(8):
    s = input().strip()
    j = 0
    while j < 8:
        if s[j] == 'W' or s[j] == 'B':
            if top[j] == -1:
                top[j] = i
                top_let[j] = s[j]

            down[j] = i
            down_let[j] = s[j]

        j += 1

min_w = 10
max_b = -1
for i in range(8):
    if top_let[i] == 'W' and min_w > top[i]:
        min_w = top[i]

    if down_let[i] == 'B' and max_b < down[i]:
        max_b = down[i]

if min_w > 8 - max_b - 1:
    print('B')
else:
    print('A')

field = [input() for i in range(8)]
field = [[field[y][x] for y in range(8)] for x in range(8)]

wa = float('+inf')
wb = float('+inf')


for row in field:
    row = ''.join(row)
    if 'W' in row:
        if ('B' in row) and row.index('W') > row.index('B'):
            pass
        else:
            nwa = row.index('W')
            wa = min(wa, nwa)
    if 'B' in row:
        if ('W' in row) and row.rindex('W') >  row.rindex('B'):
            pass
        else:
            nwb = 7 - row.rindex('B')
            wb = min(wb, nwb)


if wa <= wb:
    print('A')
else:
    print('B')


# -*- coding: utf-8 -*-
"""
Created on Sat Oct 31 15:01:05 2015

@author: gmarti
"""

import sys
from sys import stdin, stdout


chess = []
for i in range(8):
    chess.append([x for x in stdin.readline().rstrip().split()])


white_dist = []
black_dist = []

for i in range(8):
    for j in range(8):
        if chess[i][0][j] == "W":
            #check if black above
            is_black_above = False
            for k in range(0, i):
                if chess[k][0][j] == "B":
                    is_black_above = True
            if not is_black_above:
                white_dist.append(i)
                
        if chess[i][0][j] == "B":
            #check if white below
            is_white_below = False
            for k in range(i+1,8):
                if chess[k][0][j] == "W":
                    is_white_below = True
            if not is_white_below:
                black_dist.append(7-i)
                
            
if (min(white_dist) <= min(black_dist)):
    stdout.write("A\n") 
else:
    stdout.write("B\n")


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time

#   = input()
#   = int(input())

#() = (i for i in input().split())
#   = [i for i in input().split()]

#() = (int(i) for i in input().split())
a = [[ 0 for j in range(8) ] for i in range(8) ]

for i in range(8):
    b   = input()
    for j in range(8):
        a[j][i]=b[j]

start = time.time()

mW = 10
mB = 10

for i in range(8):
    flag = True
    for j in range(8):
        if a[i][j] == 'B':
            flag = False
            break
        if a[i][j] == 'W':
            break
    if flag == False:
        continue
    if mW > j:
        mW = j

for i in range(8):
    flag = True
    for j in range(8):
        if a[i][7-j] == 'W':
            flag = False
            break
        if a[i][7-j] == 'B':
            break
    if flag == False:
        continue
    if mB > j:
        mB = j


if mW <= mB:
    print('A')
else:
    print('B')
#print(ans)
finish = time.time()
#print(finish - start)


board = [input(),input(),input(),input(),input(),input(),input(),input()]
b = -99
for i in range(8):
    for j in range(7,-1,-1):
        piece = board[j][i]
        if piece == 'W':
            break
        if piece == 'B':
            b = max(b,j)
            break
b = 7-b
w = 99
for i in range(8):
    for j in range(8):
        piece = board[j][i]
        if piece == 'B':
            break
        if piece == 'W':
            w = min(w,j)
if b < w:
    print('B')
else:
    print('A')


table = []
for _ in range(8):
  table.append(input())

ocrA = []
ocrB = []
A = 8
B = 8

import re
for i in range(8):
  for j in range(8):
    if table[i][j] == "W":
      ocrA.append(j)
    elif table[i][j] == "B":
      ocrB.append(j)

  #print(ocrA, ocrB)

  while ocrA != []:
    asteps = 0
    for j in range(i-1, -1, -1):
      if table[j][ocrA[0]] != ".":
        asteps = -1
        break
      asteps += 1
    if asteps != -1 and asteps < A:
      A = asteps
    ocrA.pop(0)
  
  while ocrB != []:
    bsteps = 0
    for j in range(i+1, 8):
      if table[j][ocrB[0]] != ".":
        bsteps = -1
        break
      bsteps += 1
    if bsteps != -1 and bsteps < B:
      B = bsteps
    ocrB.pop(0)

if A <= B:
  print("A")
else:
  print("B")

board = [input() for i in range(8)]
A = B = 1000
for i in range(8):
    for j in range(8):
        if board[j][i] == 'B':
            break
        if board[j][i] == 'W':
            A = min(A, j)
    for j in range(8):
        if board[7 - j][i] == 'W':
            break
        if board[7 - j][i] == 'B':
            B = min(B, j)

if A <= B:
    print('A')
else:
    print('B')

x = []
for i in range(8):
    x.append(input())
# B
B_mov = 1000
for i in range(8):
    for j in range(8):
        if x[i][j] == "B":
            count = 0
            for k in range(i + 1, 8):
                if x[k][j] == ".":
                    count += 1
                else:
                    break
            else:
                if count < B_mov:
                    B_mov = count
            count = 0
# W
A_mov = 1000
for i in range(8):
    for j in range(8):
        if x[i][j] == "W":
            count = 0
            for k in range(i - 1, -1, -1):
                if x[k][j] == ".":
                    count += 1
                else:
                    break
            else:
                if count < A_mov:
                    A_mov = count
            count = 0
if A_mov > B_mov:
    print("B")
else:
    print("A")


import sys


def main():
    stdin = sys.stdin.read().split('\n')
    
    A, B = [], []
    for row in range(8):
        for col in range(8):
            if stdin[row][col] == 'W':
                A.append((row, col))
            if stdin[row][col] == 'B':
                B.append((row, col))
    
    Acount = []
    for a in A:
        if all(stdin[i][a[1]] == '.' for i in range(a[0])):
            Acount.append(a[0])
    Bcount = []
    for b in B:
        if all(stdin[i][b[1]] == '.' for i in range(b[0]+1, 8)):
            Bcount.append(7-b[0])
    
    if min(Acount) <= min(Bcount):
        print('A')
    else:
        print('B')


def __starting_point():
    main()

__starting_point()

arr=[0]*8
for i in range(8):
    arr[i]=input()
wr,wc,br,bc=[[],[],[],[]]
for i in range(8):
    for j in range(8):
        if arr[i][j]=='B':
            bc.append(j)
            br.append(i)
        if arr[i][j]=='W':
            wc.append(j)
            wr.append(i)
bl=len(bc)
wl=len(wc)
wf=8
bf=8
for i in range(bl-1,-1,-1):
    c=bc[i]
    temp=0
    for j in range(7,-1,-1):
        if arr[j][c]=='W':
            temp=j
            break
    if temp>br[i]:
        continue
    bf=7-br[i]
    break
for i in range(wl):
    c=wc[i]
    temp=8
    for j in range(8):
        if arr[j][c]=='B':
            temp=j
            break
    if temp<wr[i]:
        continue
    wf=wr[i]
    break
if bf<wf:
    print('B')
else:
    print('A')




b = [100 for i in range(8)]
w = [100 for i in range(8)]
b_temp = 0
w_temp = 0
b_min = 0
w_min = 0
field = ['' for i in range (8)]
for i in range(8):
    field[i] = input()
for i in range(8):
    for j in range(8):
        w_temp +=1
        if field[j][i] == 'B':
            w_temp = 100
        if (field[j][i] == 'W')and(w_temp < 100):
            w[i] = w_temp
            w_temp = 100
    w_temp = 0
for i in range(8):
    for j in range(8):
        b_temp += 1
        if field[7-j][i] == 'W':
            b_temp = 100
        if (field[7-j][i] == 'B')and(b_temp < 100):
            b[i] = b_temp
            b_temp = 100
    b_temp = 0        
b_min = min(b)
w_min = min(w)
if b_min < w_min:
    print('B')
else:
    print('A')




            


a = []
for i in range(8):
    a.append(input())
wmin = 8
bmin = -1
for i in range(8):
    for j in range(8):
        if (a[j][i] == 'W'):
            wmin = min(wmin, j)
            break
        elif (a[j][i] == 'B'):
            break
for i in range(8):
    for j in range(7, 0, -1):
        if (a[j][i] == 'B'):
            bmin = max(bmin, j)
            break
        elif (a[j][i] == 'W'):
            break
if (7 - bmin < wmin):
    print("B")
else:
    print("A")