#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct node {
  int cnt, ls[11], rs[11], f[44];
  node() {
    for (int i = 0; i < 11; ++i) ls[i] = rs[i] = 0;
  }
} tree[N << 2];
int find(int *f, int x) { return x == f[x] ? x : f[x] = find(f, f[x]); }
void Merge(int *f, int a, int b) {}
int n;
int b[44];
int g[12][N];
node up(int mid, node L, node R) {
  node t;
  for (int i = 1; i < 44; ++i) t.f[i] = i;
  for (int i = 1; i <= n; ++i) {
    R.ls[i] += n * 2;
    R.rs[i] += n * 2;
  }
  t.cnt = L.cnt + R.cnt;
  for (int i = 1; i <= n; ++i)
    if (g[i][mid] == g[i][mid + 1]) {
      int fa = find(t.f, L.rs[i]), fb = find(t.f, R.ls[i]);
      if (fa == fb) continue;
      t.f[fa] = fb;
      t.cnt--;
    }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    t.ls[i] = find(t.f, L.ls[i]);
    t.rs[i] = find(t.f, R.rs[i]);
    b[cnt++] = t.ls[i];
    b[cnt++] = t.rs[i];
  }
  sort(b, b + cnt);
  int l = unique(b, b + cnt) - b;
  for (int i = 1; i <= n; ++i) {
    t.ls[i] = lower_bound(b, b + cnt, t.ls[i]) - b + 1;
    t.rs[i] = lower_bound(b, b + cnt, t.rs[i]) - b + 1;
  }
  return t;
}
void build(int l, int r, int rt) {
  if (l == r) {
    tree[rt].cnt = 1;
    tree[rt].ls[1] = tree[rt].rs[1] = tree[rt].f[1] = tree[rt].cnt;
    for (int i = 1; i < 44; ++i) tree[rt].f[i] = i;
    for (int i = 2; i <= n; ++i)
      if (g[i][l] == g[i - 1][l]) {
        tree[rt].ls[i] = tree[rt].rs[i] = tree[rt].ls[i - 1];
        tree[rt].f[i] = find(tree[rt].f, i - 1);
      } else
        tree[rt].ls[i] = tree[rt].rs[i] = tree[rt].f[i] = ++tree[rt].cnt;
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, (rt << 1));
  build(mid + 1, r, (rt << 1 | 1));
  tree[rt] = up(mid, tree[(rt << 1)], tree[(rt << 1 | 1)]);
}
node query(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) return tree[rt];
  int mid = l + r >> 1;
  if (R <= mid)
    return query(L, R, l, mid, (rt << 1));
  else if (L > mid)
    return query(L, R, mid + 1, r, (rt << 1 | 1));
  else {
    node a = query(L, R, l, mid, (rt << 1));
    node b = query(L, R, mid + 1, r, (rt << 1 | 1));
    return up(mid, a, b);
  }
}
int main() {
  int m, q, l, r;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) scanf("%d", &g[i][j]);
  build(1, m, 1);
  while (q--) {
    scanf("%d%d", &l, &r);
    printf("%d\n", query(l, r, 1, m, 1).cnt);
  }
  return 0;
}
