#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
using namespace std;
long long n, m, q, a[11][100005], _next, par[2000005], siz[2000005];
struct tree {
  long long val, l, r, arr[2][11];
  tree() {
    val = l = r = 0;
    for (long long i = 0; i < 2; i++) {
      for (long long j = 1; j <= 10; j++) {
        arr[i][j] = 0;
      }
    }
  }
} aint[4 * 100005];
long long parinte(long long x) {
  if (x != par[x]) {
    par[x] = parinte(par[x]);
  }
  return par[x];
}
void join(long long x, long long y) {
  x = parinte(x);
  y = parinte(y);
  if (x == y)
    return;
  else {
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
  }
}
tree merge(tree st, tree dr) {
  if (st.val == 0) return dr;
  if (dr.val == 0) return st;
  tree ANS;
  ANS.val = (st.val + dr.val);
  for (long long i = 1; i <= n; i++) {
    par[st.arr[0][i]] = st.arr[0][i];
    par[st.arr[1][i]] = st.arr[1][i];
    par[dr.arr[0][i]] = dr.arr[0][i];
    par[dr.arr[1][i]] = dr.arr[1][i];
    siz[st.arr[0][i]] = siz[st.arr[1][i]] = siz[dr.arr[0][i]] =
        siz[dr.arr[1][i]] = 0;
  }
  for (long long i = 1; i <= n; i++) {
    siz[st.arr[0][i]]++;
    siz[st.arr[1][i]]++;
    siz[dr.arr[0][i]]++;
    siz[dr.arr[1][i]]++;
  }
  for (long long i = 1; i <= n; i++) {
    if (a[i][st.r] == a[i][dr.l]) {
      if (parinte(st.arr[1][i]) != parinte(dr.arr[0][i])) ANS.val--;
      join(st.arr[1][i], dr.arr[0][i]);
    }
  }
  for (long long i = 1; i <= n; i++) {
    ANS.arr[0][i] = parinte(st.arr[0][i]);
    ANS.arr[1][i] = parinte(dr.arr[1][i]);
  }
  ANS.l = st.l, ANS.r = dr.r;
  return ANS;
}
void build(long long l, long long r, long long nod) {
  if (l == r) {
    aint[nod].l = aint[nod].r = l;
    for (long long i = 1; i <= n; i++) {
      if (a[i][l] == a[i - 1][l]) {
        aint[nod].arr[0][i] = aint[nod].arr[1][i] = (_next);
      } else {
        aint[nod].arr[0][i] = aint[nod].arr[1][i] = (++_next);
        aint[nod].val++;
      }
    }
  } else {
    long long mid = l + (r - l) / 2;
    build(l, mid, 2 * nod);
    build(mid + 1, r, 2 * nod + 1);
    aint[nod] = merge(aint[2 * nod], aint[2 * nod + 1]);
  }
}
tree query(long long l, long long r, long long le, long long ri,
           long long nod) {
  if (l > ri || r < le) {
    tree TZ;
    return TZ;
  } else if (l >= le && r <= ri) {
    return aint[nod];
  } else {
    long long mid = l + (r - l) / 2;
    return merge(query(l, mid, le, ri, 2 * nod),
                 query(mid + 1, r, le, ri, 2 * nod + 1));
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  srand(chrono::steady_clock::now().time_since_epoch().count());
  cin >> n >> m >> q;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  build(1, m, 1);
  for (long long i = 1; i <= q; i++) {
    long long l, r;
    cin >> l >> r;
    cout << query(1, m, l, r, 1).val << '\n';
  }
}
