/****************************************************
 * Author  : duc viet
 * From    : HSGS Tran Phu, Hai Phong
 * Created : 2026-11-03 10:47:53
 ****************************************************/

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

#define                        LOCAL
#define                       fi first
#define                       se second
#define                      left ___left
#define                      right ___right
#define                      int long long
#define           TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define                    MASK(i)  (1LL << (i))
#define                 BIT(x, i)  ((x) >> (i) & 1)
#define          __builtin_popcount  __builtin_popcountll
#define                 ALL(v)  (v).begin(), (v).end()
#define              REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define             REPD(i, n)  for (int i = (n); i-- > 0; )
#define             FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i)
#define          FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; )
#define            FORE(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i)
#define         FORDE(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i)
#define             scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define            print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)

template <class U, class V> scan_op(pair <U, V>)  { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>)  { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")";  else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }

#ifdef LOCAL
    // #include "debug.h"
#else
    #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
    #define DB(...) 23
    #define db(...) 23
    #define debug(...) 23
#endif


const int N = 1e6 + 5;
const int mod = 1e9 + 7;


char grid[1010][1010];
int d[1010][1010];

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

int n, m, q;


void bfs() {
    deque<pair<int, int>> dq;

    for (int i = 1 ; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (grid[i][j] == '*') {
                d[i][j] = 0;
                dq.push_back({i, j});
            }
            else d[i][j] = LLONG_MAX;
        }
    }

    while (!dq.empty()) {
        pair<int, int> p = dq.front(); dq.pop_front(); 

        int x = p.first;
        int y = p.second;

        for (int i = 0; i < 4; i++) {
            int xi = x + dx[i];
            int yi = y + dy[i];

            if (xi < 1 || xi > m || yi < 1 || yi > n) continue; 
            
            int w;
            if (grid[xi][yi] != grid[x][y]) w = 1;
            else w = 0;

            if (d[x][y] + w < d[xi][yi]) {
                d[xi][yi] = d[x][y] + w;

                if (w == 0) dq.push_front({xi, yi});
                else dq.push_back({xi, yi}); 
            }
        }
    }
}


void Solve(){
    cin >> m >> n >> q; 

    for (int i = 1; i <= m; i++) cin >> (grid[i] + 1);
    bfs();

    while (q--) {
        int x, y ; cin >> x >> y;

        cout << d[x][y] << endl; 
    }
}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    // file(ILOVEHD);
    
    Solve();

    #ifdef LOCAL
        cerr << "\n-------------------\n";
        cerr << "Time elapsed: " << TIME << " s\n";
    #endif
    
    return 0;
}