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

static const int dy[] = { -1, 0, 1, 0, 0}, dx[] = { 0, -1, 0, 1, 0 };

struct state { int a, b, c, 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 (newa == newb || newa == newc || newb == newc) continue; //Rule 1.
                                                if (newa == now.b && newb == now.a) continue; //Rule 2.
                                                if (newa == now.c && newc == now.a) continue; //
                                                if (newb == now.c && newc == now.b) continue; //

                                                if (used[newa][newb][newc]) continue;
                                                used[newa][newb][newc] = true;
                                                q.push((state) { newa, newb, newc, now.step + 1 });
                                        }
                                }
                        }
                }
                cout << ans << endl;
        }
        return 0;
}

Measured memory_bytes: 23628