def matrix_protect(Matrix, a):
Matrix.insert(0, [a]*len(Matrix[0]))
Matrix.append([a]*len(Matrix[0]))
for i in Matrix:
i.insert(0,a)
i.append(a)
def check(i,j):
global cnt
p[i][j] = '.'
cnt += 1
if p[i-1][j-1] == 'W':
check(i-1,j-1)
if p[i][j-1] == 'W':
check(i,j-1)
if p[i+1][j-1] == 'W':
check(i+1,j-1)
if p[i-1][j] == 'W':
check(i-1,j)
if p[i+1][j] == 'W':
check(i+1,j)
if p[i-1][j+1] == 'W':
check(i-1,j+1)
if p[i][j+1] == 'W':
check(i,j+1)
if p[i+1][j+1] == 'W':
check(i+1,j+1)
s = []
t = int(input())
while (t>0):
n,m = map(int,input().split())
p = [list(input())for j in range(n)]
# print(p)
matrix_protect(p,'.')
# print(p)
for i in range(1,n+1):
for j in range(1,m+1):
if p[i][j] == 'W':
cnt = 0
check(i,j)
s.append(cnt)
print(max(s)if s != [] else 0)
t -=1
为什么总是WA啊,绝望