import java.util.Scanner;
public class main
{
static final int MAX_W = 12;
static final int MAX_H = 19;
static final int MAX_K = 10000;
static final int DR[] = {0, 1, 1, 1};
static final int DC[] = {1, -1, 0, 1};
private static char[][] G;
private static boolean[][] M;
private static int[] P;
private static int[] S;
private static boolean check(int v, int l, int r) {
return l <= v && v <= r;
}
private static void init(int w, int h) {
G = new char[h][w];
M = new boolean[h][w];
for (int row = 0; row < h; ++row)
for (int col = 0; col < w; ++col) {
G[row][col] = 0;
M[row][col] = false;
}
}
private static int position(int w, int h, int col) {
int pos = h;
while (pos != 0 && G[pos - 1][col] == 0)
--pos;
return pos;
}
private static int play(int w, int h, String c, int p, int s) {
int pos = position(w, h, p);
if (pos + 3 > h)
return -1;
int score = 0;
if (c.equals("***")) {
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] = 0;
++score;
}
} else {
for (int row = pos; row < pos + 3; ++row)
G[row][p] = c.charAt((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] = 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] != 0) {
boolean 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] = 0;
M[row][col] = false;
}
score += combo*count;
if (count == 0)
break;
}
return 47*score;
}
private static int solve() {
Scanner in = new Scanner(System.in);
int w, h;
w = in.nextInt();
h = in.nextInt();
int k;
k = in.nextInt();
in.nextLine();
init(w, h);
P = new int[k];
S = new int[k];
int len = 0;
for (int i = 0; i < k; ++i) {
String c;
c = in.nextLine();
P[i] = 0;
S[i] = 0;
int best = position(w, h, P[i]);
for (int col = 1; col < w; ++col) {
int pos = position(w, h, col);
if (pos < best) {
best = pos;
P[i] = col;
}
}
int r = play(w, h, c, P[i], 0);
if (r == -1)
break;
else
++len;
}
return len;
}
public static void main(String[] args)
{
int t = solve();
System.out.println(t);
for (int i = 0; i < t; ++i)
System.out.println((P[i] + 1) + " " + S[i]);
}
}