def getint(): return int(input()) def getints(): return list(map(int, input().split())) def getintsm1(): return [int(x)-1 for x in input().split()] T = int(input()) import numpy as np def get(yx): return F[yx[0]][yx[1]] if all((0 <= yx) & (yx < [R,C])) else '#' dirs = list(map(np.array, [[0,1],[0,-1],[1,0],[-1,0]])) for caseno in range(T): R, C = getints() F = [input() for _ in range(R)] ifins = {} istarts = {} for y in range(R): for x in range(C): c = F[y][x] if c.isalpha(): [istarts, ifins][c.isupper()][c] = np.array([y,x]) result = [] for fchar, f in ifins.items(): success = {tuple(f)} pending = [f] while pending: x = pending.pop() for d in dirs: y = x while True: y = y + d c = get(y) if c in '*#' or tuple(y) in success: break if c != '*': y = y - d while any(y != x): success.add(tuple(y)) pending.append(y) y = y - d for schar, s in istarts.items(): if tuple(s) in success: result.append(schar + fchar) print(f"Case #{caseno + 1}:", *sorted(result or ['NONE']))