import math N, T = input().split(' ') N = int(N) city = "" for i in range(N): city += input() machines = [] for i in range(len(city)): if city[i] == T: machines.append((i % N, math.floor(i/N))) def trans(x, y): return y*N + x def canMove(fro, to): if T == 'R': return fro[0]==to[0] or fro[1]==to[1] elif T == 'Q': return fro[0]==to[0] or fro[1]==to[1] or abs(fro[0]-to[0])==abs(fro[1]-to[1]) elif T == 'B': return abs(fro[0]-to[0])==abs(fro[1]-to[1]) elif T == 'N': return (fro[0]-to[0]==1 and fro[1]-to[1]==2) or (fro[0]-to[0]==2 and fro[1]-to[1]==1) elif T == 'K': return abs(fro[0]-to[0]) < 2 and abs(fro[1]-to[1]) < 2 def moveTo(what, where, l): for m in machines: if (not (m in l)) and canMove(what, m): l.append(m) moveTo(m, what, l) moves.append("{} {} {} {}".format(what[1]+1, what[0]+1, where[1]+1, where[0]+1)) machines.remove(what) moves = [] active = machines[0] moved = False while len(machines) > 1: moved = False for m in machines: if active != m and canMove(active, m): moveTo(active, m, [active, m]) active = m moved = True break if not moved: print("NO") exit(0) print("YES") print(*moves, sep='\n')