#include <bits/stdc++.h>
using namespace std;
#define MAX_W 12
#define MAX_H 19
#define MAX_K 10000
const int DR[] = {0, 1, 1, 1};
const int DC[] = {1, -1, 0, 1};
char G[MAX_H][MAX_H];
bool M[MAX_H][MAX_H];
int P[MAX_K];
int S[MAX_K];
bool check(int v, int l, int r) {
return l <= v && v <= r;
}
void init(int w, int h) {
for (int row = 0; row < h; ++row)
for (int col = 0; col < w; ++col) {
G[row][col] = 0;
M[row][col] = false;
}
}
int position(int w, int h, int col) {
auto pos = h;
while (pos != 0 && G[pos - 1][col] == 0)
--pos;
return pos;
}
int play(int w, int h, string c, int p, int s) {
auto pos = position(w, h, p);
if (pos + 3 > h)
return -1;
int score = 0;
if (c == "***") {
char z = pos == 0 ? -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[(row - pos + s) % 3];
}
for (int combo = 1; ; ++combo) {
for (int col = 0; col < w; ++col) {
int 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) {
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] = 0;
M[row][col] = false;
}
score += combo*count;
if (count == 0)
break;
}
return 47*score;
}
int solve() {
int w, h;
cin >> w >> h;
int k;
cin >> k;
init(w, h);
int len = 0;
for (int i = 0; i < k; ++i) {
string c;
cin >> c;
P[i] = 0;
S[i] = 0;
int best = position(w, h, P[i]);
for (int col = 1; col < w; ++col) {
auto pos = position(w, h, col);
if (pos < best) {
best = pos;
P[i] = col;
}
}
auto r = play(w, h, c, P[i], 0);
if (r == -1)
break;
else
++len;
}
return len;
}
int main() {
auto t = solve();
cout << t << endl;
for (int i = 0; i < t; ++i)
cout << (P[i] + 1) << ' ' << S[i] << endl;
return 0;
}