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

#define rep(i, n) for (int i = 0; i < (n); i ++) 
static const int dy[] = { -1, 0, 1, 0, 0}, dx[] = { 0, -1, 0, 1, 0 };

struct state {
        int a;
        int b;
        int c;
        int step;
};

bool used[260][260][260];

int main() {
        int w, h, n;
        while (true) {
                cin >> w >> h >> n;
                cin.ignore();
                if (n == 0) break;
                vector<string> m(h);
                for (int i = 0; i < h; i ++) {
                        getline(cin, m[i]);
                }
                int as, ag, bs = (h - 1) * w + (w - 1), bg = (h - 1) * w + (w - 1), cs = 0, cg = 0;
                for (int i = 0; i < h; i ++) {
                        for (int j = 0; j < w; j ++) {
                                if (m[i][j] == 'A') as = i * w + j;
                                if (m[i][j] == 'a') ag = i * w + j;
                                if (m[i][j] == 'B') bs = i * w + j;
                                if (m[i][j] == 'b') bg = i * w + j;
                                if (m[i][j] == 'C') cs = i * w + j;
                                if (m[i][j] == 'c') cg = i * w + j;
                        }
                }
                queue<state> q;
                memset(used, false, sizeof(used));
                used[as][bs][cs] = true;
                q.push((state) { as, bs, cs });
                int ans = -1;
                while (!q.empty()) {
                        state now = q.front(); q.pop();
                        if (now.a == ag && now.b == bg && now.c == cg) {
                                ans = now.step;
                                break;
                        }
                        int noway = now.a / w, nowax = now.a % w;
                        int nowby = now.b / w, nowbx = now.b % w;
                        int nowcy = now.c / w, nowcx = now.c % w;
                        for (int da = 0; da < 5; da ++) {
                                int neway = noway + dy[da], newax = nowax + dx[da];
                                if (neway < 0 || h <= neway || newax < 0 || w <= newax) continue;
                                if (m[neway][newax] == '#') continue;
                                for (int db = 0; db < 5; db ++) {
                                        int newby = nowby + dy[db], newbx = nowbx + dx[db];
                                        if (newby < 0 || h <= newby || newbx < 0 || w <= newbx) continue;
                                        if (n > 1) if (m[newby][newbx] == '#') continue;
                                        for (int dc = 0; dc < 5; dc ++) {
                                                int newcy = nowcy + dy[dc], newcx = nowcx + dx[dc];
                                                if (newcy < 0 || h <= newcy || newcx < 0 || w <= newcx) continue;
                                                if (n > 2) if (m[newcy][newcx] == '#') continue;
                                                int newa = neway * w + newax;
                                                int newb = newby * w + newbx;
                                                int newc = newcy * w + newcx;
                                                if (used[newa][newb][newc]) continue;
                                                if (newa == newb || newa == newc || newb == newc) continue;
                                                if (newa == now.b && newb == now.a) continue;
                                                if (newa == now.c && newc == now.a) continue;
                                                if (newb == now.c && newc == now.b) continue;
                                                used[newa][newb][newc] = true;
                                                q.push((state) { newa, newb, newc, now.step + 1 });
                                        }
                                }
                        }
                }
                cout << ans << endl;
        }
        return 0;
}

Measured memory_bytes: 23524