def corr(x, y):
    if 0 <= x < n and 0 <= y < m:
        return True
    return False


ans = []
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for _ in range(int(input())):
    n, m = map(int, input().split())
    u = []
    for i in range(n):
        u.append(list(input()))
    ok = False
    ex_G = False
    for i in range(n):
        for j in range(m):
            if u[i][j] == 'G':
                ex_G = True
            if u[i][j] != 'B':
                continue
            for k in range(4):
                xi, yi = i + dx[k], j + dy[k]
                if not corr(xi, yi):
                    continue
                if u[xi][yi] == 'G':
                    ok = True
                    break
                if u[xi][yi] == 'B':
                    continue
                u[xi][yi] = '#'
            if ok:
                break
        if ok:
            break
    if ok:
        ans.append('NO')
        continue
    if not ex_G:
        ans.append('YES')
        continue
    if u[n - 1][m - 1] == '#':
        ans.append('NO')
        continue
    d = []
    for i in range(n):
        d.append([0] * m)
    d[n - 1][m - 1] = 1
    q = [(n - 1, m - 1)]
    q0 = 0
    while len(q) > q0:
        x, y = q[q0]
        q0 += 1
        for k in range(4):
            xi, yi = x + dx[k], y + dy[k]
            if not corr(xi, yi) or d[xi][yi] == 1:
                continue
            d[xi][yi] = 1
            q.append((xi, yi))
    ok_ans = False
    for i in range(n):
        for j in range(m):
            if u[i][j] == 'G' and d[i][j] == 0:
                ok_ans = True
                break
        if ok_ans:
            break
    if ok_ans:
        ans.append('NO')
    else:
        ans.append('YES')
print('\n'.join(map(str, ans)))

