using System;
class main
{
const int MAX_W = 12;
const int MAX_H = 19;
const int MAX_K = 10000;
static readonly int[] DR = {0, 1, 1, 1};
static readonly int[] DC = {1, -1, 0, 1};
static char[,] G;
static bool[,] M;
static int[] P;
static int[] S;
static bool check(int v, int l, int r) {
return l <= v && v <= r;
}
static void init(int w, int h) {
G = new char[h, w];
M = new bool[h, w];
for (int row = 0; row < h; ++row)
for (int col = 0; col < w; ++col) {
G[row, col] = (char)0;
M[row, col] = false;
}
}
static int position(int w, int h, int col) {
var pos = h;
while (pos != 0 && G[pos - 1, col] == 0)
--pos;
return pos;
}
static int play(int w, int h, string c, int p, int s) {
var pos = position(w, h, p);
if (pos + 3 > h)
return -1;
int score = 0;
if (c == "***") {
char z = pos == 0 ? (char)1 : G[pos - 1, p];
for (int row = 0; row < h; ++row)
for (int col = 0; col < w; ++col)
if (G[row, col] == z) {
G[row, col] = (char)0;
++score;
}
} else {
for (int row = pos; row < pos + 3; ++row)
G[row, p] = c[(row - pos + s) % 3];
}
for (int combo = 1; ; ++combo) {
for (int col = 0; col < w; ++col) {
pos = 0;
for (int row = 0; row < h; ++row)
if (G[row, col] != 0) {
if (pos != row) {
G[pos, col] = G[row, col];
G[row, col] = (char)0;
}
++pos;
}
}
int count = 0;
for (int row = 0; row < h; ++row)
for (int col = 0; col < w; ++col)
for (int dir = 0; dir < 4; ++dir)
if (G[row, col] != (char)0) {
bool fail = false;
for (int j = 0, rr = row, cc = col; j < 3; ++j, rr += DR[dir], cc += DC[dir]) {
if (!check(rr, 0, h - 1) || !check(cc, 0, w - 1) || G[rr, cc] != G[row, col]) {
fail = true;
break;
}
}
if (!fail) {
++count;
for (int j = 0, rr = row, cc = col; j < 3; ++j, rr += DR[dir], cc += DC[dir])
M[rr, cc] = true;
}
}
for (int row = 0; row < h; ++row)
for (int col = 0; col < w; ++col)
if (M[row, col]) {
G[row, col] = (char)0;
M[row, col] = false;
}
score += combo*count;
if (count == 0)
break;
}
return 47*score;
}
static int solve() {
string[] line = Console.ReadLine().Split(' ');
int w, h;
w = Int32.Parse(line[0]);
h = Int32.Parse(line[1]);
int k = Int32.Parse(Console.ReadLine());
P = new int[k];
S = new int[k];
init(w, h);
int len = 0;
for (int i = 0; i < k; ++i) {
string c = Console.ReadLine();
P[i] = 0;
S[i] = 0;
int best = position(w, h, P[i]);
for (int col = 1; col < w; ++col) {
var pos = position(w, h, col);
if (pos < best) {
best = pos;
P[i] = col;
}
}
var r = play(w, h, c, P[i], 0);
if (r == -1)
break;
else
++len;
}
return len;
}
public static void Main(string[] args)
{
var t = solve();
Console.WriteLine(t);
for (int i = 0; i < t; ++i)
Console.WriteLine("{0} {1}", P[i] + 1, S[i]);
}
}