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

moves = []
active = machines[-1]
moved = False
while len(machines) > 1:
    moved = False
    for m in machines:
        if active != m and canMove(active, m):
            moves.append("{} {} {} {}".format(active[1]+1, active[0]+1, m[1]+1, m[0]+1))
            machines.remove(active)
            active = m
            moved = True
            break
    if not moved:
        print("NO")
        exit(0)

print("YES")
print(*moves, sep='\n')
                












    


