def instr(string, pos):
    return string[:pos] + "#" + string[pos+1:]

def color(matrix, x, y):
    queue = [(x,y)]
    while len(queue) > 0:
        x,y = queue.pop(0)
        matrix[y] = instr(matrix[y], x)
        if x > 0 and matrix[y][x-1] == " ":
            if (x-1,y) not in queue:
                queue.append((x-1, y))
        if x+1 < len(matrix[y]) and matrix[y][x+1] == " ":
            if (x+1,y) not in queue:
                queue.append((x+1, y))
        if y > 0 and matrix[y-1][x] == " ":
            if (x, y-1) not in queue:
                queue.append((x, y-1))
        if y+1 < len(matrix) and matrix[y+1][x] == " ":
            if (x, y+1) not in queue:
                queue.append((x, y+1))
    

for _ in range(int(input())):
    row_count, col_count = map(int, input().split())
    rows = []
    for _ in range(row_count):
        rows.append(input())
        rows[-1] = rows[-1].translate(rows[-1].maketrans("+", "#"))
        error = False
        for letter in rows[-1]:
            if letter not in "# ":
                error = True
        if error or (len(rows[-1]) != col_count):
            if error:
                print("bad char")
            print("offending row:", rows[-1])
    count = 0
    for letter in range(col_count):
        if rows[0][letter] == " ":
            color(rows, letter, 0)
            count = count + 1
        if rows[-1][letter] == " ":
            color(rows, letter, row_count - 1)
            count = count + 1
    for letter in range(row_count):
        if rows[letter][0] == " ":
            color(rows, 0, letter)
            count = count + 1
        if rows[letter][-1] == " ":
            color(rows, col_count - 1, letter)
            count = count + 1
    print(count, "entries")
    
            
