#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int MAXN = 100005;
const int MAXM = 5005;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const double FINF = 10000000;
const long long MOD = 1000000007;
const double PI = acos(-1);
struct lx {
  int rs[11], ls[11], sum;
} tree[MAXN * 4];
int n;
int mp[11][MAXN], tot;
int fa[MAXN * 10];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void mix(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx != fy) {
    fa[fx] = fy;
  }
}
lx pushup(lx a, lx b, int mid) {
  lx res;
  res.sum = a.sum + b.sum;
  for (int i = 1; i <= n; ++i) {
    fa[a.ls[i]] = a.ls[i];
    fa[b.ls[i]] = b.ls[i];
    fa[a.rs[i]] = a.rs[i];
    fa[b.rs[i]] = b.rs[i];
  }
  for (int i = 1; i <= n; ++i)
    if (mp[i][mid] == mp[i][mid + 1]) {
      if (find(a.rs[i]) != find(b.ls[i])) {
        res.sum--;
        mix(a.rs[i], b.ls[i]);
      }
    }
  for (int i = 1; i <= n; ++i) {
    res.ls[i] = find(a.ls[i]);
    res.rs[i] = find(b.rs[i]);
  }
  return res;
}
void build(int l, int r, int id) {
  if (l == r) {
    for (int i = 1; i <= n; ++i) {
      if (mp[i - 1][l] == mp[i][l])
        tree[id].ls[i] = tree[id].rs[i] = tree[id].ls[i - 1];
      else
        tree[id].ls[i] = tree[id].rs[i] = ++tot, tree[id].sum++;
    }
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, id << 1);
  build(mid + 1, r, id << 1 | 1);
  tree[id] = pushup(tree[id << 1], tree[id << 1 | 1], mid);
}
lx query(int l, int r, int id, int L, int R) {
  if (L <= l && r <= R) {
    return tree[id];
  }
  int mid = (l + r) >> 1;
  if (R <= mid)
    return query(l, mid, id << 1, L, R);
  else if (L > mid)
    return query(mid + 1, r, id << 1 | 1, L, R);
  else {
    return pushup(query(l, mid, id << 1, L, R),
                  query(mid + 1, r, id << 1 | 1, L, R), mid);
  }
}
int main() {
  memset(tree, 0, sizeof(tree));
  tot = 0;
  int m, q, x, y;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      scanf("%d", &mp[i][j]);
    }
  }
  build(1, m, 1);
  while (q--) {
    scanf("%d%d", &x, &y);
    lx ans = query(1, m, 1, x, y);
    printf("%d\n", ans.sum);
  }
  return 0;
}
