#include <iostream>
#include <array>
#include <vector>
#include <cctype>
#include <map>
#include <queue>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
using namespace std;

struct point_t {
    int y, x;
};
point_t operator + (point_t const & a, point_t const & b) {
    return (point_t){ a.y + b.y, a.x + b.x };
}
bool operator == (point_t const & a, point_t const & b) {
    return make_pair(a.y, a.x) == make_pair(b.y, b.x);
}
bool operator < (point_t const & a, point_t const & b) {
    return make_pair(a.y, a.x) < make_pair(b.y, b.x);
}
static point_t dp[5] = { {-1,0}, {1,0}, {0,1}, {0,-1}, {0,0} };

struct state_t {
    array<point_t,3> a;
    int cost;
    int dist;
};
#define MAGIC_WEIGHT 1.3
bool operator < (state_t const & a, state_t const & b) {
    return MAGIC_WEIGHT * a.cost + a.dist > MAGIC_WEIGHT * b.cost + b.dist;
}
bool is_valid_move(int i, int j, array<point_t,3> const & s, array<point_t,3> const & t) {
    if (t[i] == t[j]) return false;
    if (t[i] == s[j] and t[j] == s[i]) return false;
    return true;
}

int main() {
    while (true) {
        int w, h, n; cin >> w >> h >> n; cin.ignore();
        if (w == 0 and h == 0 and n == 0) break;
        assert (1 <= n and n <= 3);
        vector<string> c(h);
        repeat (i,h) getline(cin, c[i]);

        array<point_t,3> start;
        array<point_t,3> goal;
        map<point_t,int> ix;
        repeat (y,h) repeat (x,w) {
            if (islower(c[y][x])) {
                start[c[y][x] - 'a'] = { y, x };
            } else if (isupper(c[y][x])) {
                goal[c[y][x] - 'A'] = { y, x };
            }
            if (c[y][x] != '#') {
                int i = ix.size();
                ix[(point_t){ y, x }] = i;
            }
        }
        repeat_from (i,n,3) {
            start[i] = ix.begin()->first; // fill with some non-wall cell
            goal[i]  = ix.begin()->first;
        }

        vector<vector<int> > dist[3]; // from goal
        repeat (i,3) {
            dist[i].resize(h, vector<int>(w, 1000000007));
            queue<point_t> que; // bfs
            que.push(goal[i]);
            dist[i][goal[i].y][goal[i].x] = 0;
            while (not que.empty()) {
                point_t p = que.front(); que.pop();
                repeat (j,4) {
                    auto q = p + dp[j];
                    if (c[q.y][q.x] == '#') continue;
                    if (dist[i][q.y][q.x] == 1000000007) {
                        dist[i][q.y][q.x] = dist[i][p.y][p.x] + 1;
                        que.push(q);
                    }
                }
            }
        }

        vector<vector<vector<bool> > > used(ix.size(), vector<vector<bool> >(ix.size(), vector<bool>(ix.size())));

        priority_queue<state_t> que; {
            state_t initial = { start, 0, 0 };
            repeat (i,3) initial.dist += dist[i][start[i].y][start[i].x];
            used[ix[start[0]]][ix[start[1]]][ix[start[2]]] = true;
            que.push(initial);
        }
        while (not que.empty()) {
            state_t st = que.top(); que.pop();
            array<point_t,3> & s = st.a;
            if (s == goal) {
                cout << st.cost << endl;
                break;
            }
            state_t tt = st;
            tt.cost += 1;
            array<point_t,3> & t = tt.a;
            repeat (i,5) { // a
                t[0] = s[0] + dp[i];
                if (c[t[0].y][t[0].x] == '#') continue;
                repeat (j,5) { // b
                    if (n < 2 and j != 4) continue;
                    t[1] = s[1] + dp[j];
                    if (c[t[1].y][t[1].x] == '#') continue;
                    if (not is_valid_move(0, 1, s, t)) continue;
                    repeat (k,5) { // c
                        if (n < 3 and k != 4) continue;
                        t[2] = s[2] + dp[k];
                        if (c[t[2].y][t[2].x] == '#') continue;
                        if (n == 3 and not is_valid_move(1, 2, s, t)) continue;
                        if (n == 3 and not is_valid_move(2, 0, s, t)) continue;
                        if (used[ix[t[0]]][ix[t[1]]][ix[t[2]]]) continue;
                        used[ix[t[0]]][ix[t[1]]][ix[t[2]]] = true;
                        tt.dist = 0;
                        repeat (i,3) tt.dist = max(tt.dist, dist[i][t[i].y][t[i].x]);
                        que.push(tt);
                    }
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 7908