W = 12
H = 19
DR = [0, 1, 1, 1]
DC = [1, -1, 0, 1]
def check(v, l, r):
return l <= v and v <= r
def init(w, h):
global G
global M
G = []
M = []
for _ in range(h):
G += [[0] * w]
M += [[False] * w]
def position(w, h, col):
pos = h
while pos != 0 and G[pos - 1][col] == 0:
pos -= 1
return pos
def play(w, h, c, p, s):
pos = position(w, h, p)
if pos + 3 > h:
return -1
score = 0
if c == '***':
z = -1 if pos == 0 else G[pos - 1][p]
for row in range(h):
for col in range(w):
if G[row][col] == z:
G[row][col] = 0
score += 1
else:
for row in range(pos, pos + 3):
G[row][p] = c[(row - pos + s) % 3]
combo = 0
while True:
combo += 1
for col in range(w):
pos = 0
for row in range(h):
if G[row][col] != 0:
if pos != row:
G[pos][col] = G[row][col]
G[row][col] = 0
pos += 1
count = 0
for row in range(h):
for col in range(w):
for dir in range(4):
if G[row][col] != 0:
fail = False
rr = row
cc = col
for j in range(3):
if not check(rr, 0, h-1) or not check(cc, 0, w-1) or G[rr][cc] != G[row][col]:
fail = True
break
rr += DR[dir]
cc += DC[dir]
if not fail:
count += 1
rr = row
cc = col
for j in range(3):
M[rr][cc] = True
rr += DR[dir]
cc += DC[dir]
for row in range(h):
for col in range(w):
if M[row][col]:
G[row][col] = 0
M[row][col] = False
score += combo * count
if count == 0:
break
return 47 * score
def solve():
w, h = [int(x) for x in input().split()]
k = int(input())
init(w, h)
res = []
for _ in range(k):
c = input()
p = 0
s = 0
best = position(w, h, p)
for col in range(1, w):
pos = position(w, h, col)
if pos < best:
best = pos
p = col
r = play(w, h, c, p, 0)
if r == -1:
break
res += [(p, s)]
return res
def main():
t = solve()
print(len(t))
for p, s in t:
print(p+1, s)
if __name__ == '__main__':
main()