#include<bits/stdc++.h>
using namespace std;

#define FOR(i,s,t ) for (int i = s; i < t ; i++)
using LL = long long; using VI = vector<int>;
using VL = vector<LL>; using VVI = vector<VI>;
const LL LINF = 1e18; const int INF = 1e9;
#define SZ(a) (int)a.size()

// J うく
int dist[256][256][256];
using PII = pair<int, int>;
const PII NoUse = PII(0, 0);

void solve() {
	int  W, H, N;
	while (cin >> W >> H >> N, W || H) {
		string s; getline(cin, s);
		vector<string>vs(H);
		PII sa = NoUse, sb = NoUse, sc = NoUse;
		PII ta = NoUse, tb = NoUse, tc = NoUse;
		FOR(i, 0, H) {
			getline(cin, vs[i]);
			FOR(j, 0, W) {
				if (vs[i][j] == 'a') {
					vs[i][j] = ' ';
					sa = PII(i, j);
				}
				else if (vs[i][j] == 'b') {
					vs[i][j] = ' ';
					sb = PII(i, j);
				}
				else if (vs[i][j] == 'c') {
					vs[i][j] = ' ';
					sc = PII(i, j);
				}
				else if (vs[i][j] == 'A') {
					vs[i][j] = ' ';
					ta = PII(i, j);
				}
				else if (vs[i][j] == 'B') {
					vs[i][j] = ' ';
					tb = PII(i, j);
				}
				else if (vs[i][j] == 'C') {
					vs[i][j] = ' ';
					tc = PII(i, j);
				}
			}
		}
		// 最悪を書く
		fill(**dist, **dist + 256 * 256 * 256, INF);
		using tp = tuple<PII, PII, PII>;
		queue<tp>q;
		q.push(tp( sa,sb,sc ));
		auto ha = [&](const PII & x) {
			return x.first*H + x.second;
		};
		int dy[4] = { -1,0,1,0 };
		int dx[4] = { 0,1,0,-1 };

		auto f = [&](const PII & a) {
			vector<PII>res;
			res.push_back(a);
			FOR(p, 0, 4) {
				int ny = a.first + dy[p], nx = a.second + dx[p];
				if (0 <= ny && ny < H && 0 <= nx && nx < W) {
					if (vs[ny][nx] != '#') {
						res.push_back(PII(ny, nx));
					}
				}
			}
			return res;
		};

		dist[ha(sa)][ha(sb)][ha(sc)] = 0;
		int ans = 0;
		// O(H^6*(UNCHI))

		while (!q.empty()) {
			PII aa, bb, cc;
			tie(aa, bb, cc) = q.front(); q.pop();

			int d = dist[ha(aa)][ha(bb)][ha(cc)];
			//if (ta == aa && tb == bb && tc == cc) {
			//	ans = d;
			//	break;
			//}
			// nx stateを全部持ってくる
			vector<PII>na = f(aa), nb = f(bb), nc = f(cc);
			FOR(i, 0, SZ(na)) {
				PII a = na[i];
				FOR(j, 0, SZ(nb)) {
					PII b = nb[j];
					FOR(k, 0, SZ(nc)) {// 重複しない、swapされない
						PII c = nc[k];

						// 評価順序を知らない人のモノマネをします

						//cout << "brf eval" << endl;
						//FOR(n, 0, H) {
						//	FOR(m, 0, W) {
						//		if (PII(n, m) == a)cout << "a";
						//		else if (PII(n, m) == b)cout << "b";
						//		else if (PII(n, m) == c)cout << "c";
						//		else cout << vs[n][m];
						//	}
						//	cout << endl;
						//}
						//cout << endl;

						// - 重複、ただし未使用はアレ
						if (((a != NoUse) && (a == b || a == c)))continue;
						if (((b != NoUse) && (b == c)))continue;
						// a,b a,c b,c

						// ここでゆるさないものをはじく
						// - swap
						if (a != NoUse && aa == b && bb == a)continue; // a,b
						if (a != NoUse && aa == c && cc == a)continue; // a,c
						if (b != NoUse && bb == c && cc == b)continue; // b,c

						//cout << "ok," << endl;
						//FOR(n, 0, H) {
						//	FOR(m, 0, W) {
						//		if (PII(n, m) == a)cout << "a";
						//		else if (PII(n, m) == b)cout << "b";
						//		else if (PII(n, m) == c)cout << "c";
						//		else cout << vs[n][m];
						//	}
						//	cout << endl;
						//}
						//cout << endl;
						if (dist[ha(a)][ha(b)][ha(c)] > d + 1) {
							dist[ha(a)][ha(b)][ha(c)] = d + 1;
							q.push(tp( a,b,c ));
							if (ta == a && tb == b && tc == c) {
								ans = d + 1;
								break;
							}
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 74480