#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 11;
struct node {
  int l, r, sum;
  int L[M], R[M];
} T[4 * N];
int fa[N], id[N], n, a[M][N];
int _find(int x) {
  if (x == fa[x]) return x;
  return fa[x] = _find(fa[x]);
}
node _merge(node A, node B) {
  node ans;
  ans.l = A.l, ans.r = B.r;
  ans.sum = A.sum + B.sum;
  for (int i = 1; i <= n; i++) {
    fa[i] = A.L[i];
    fa[i + n] = A.R[i];
    fa[i + 2 * n] = B.L[i] + 2 * n;
    fa[i + 3 * n] = B.R[i] + 2 * n;
  }
  int mid = A.r;
  for (int i = 1; i <= n; i++) {
    if (a[i][mid] == a[i][mid + 1]) {
      int xx = _find(i + n), yy = _find(i + 2 * n);
      if (xx != yy) {
        ans.sum--;
        fa[xx] = yy;
      }
    }
  }
  for (int i = 1; i <= 4 * n; i++) fa[i] = _find(i), id[fa[i]] = 0;
  for (int i = 1; i <= n; i++) {
    if (!id[fa[i]]) id[fa[i]] = i;
    ans.L[i] = id[fa[i]];
  }
  for (int i = 3 * n + 1; i <= 4 * n; i++) {
    if (!id[fa[i]]) id[fa[i]] = i - 2 * n;
    ans.R[i - 3 * n] = id[fa[i]];
  }
  return ans;
}
void build(int id, int l, int r) {
  T[id].l = l, T[id].r = r;
  if (l == r) {
    T[id].sum = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i][l] != a[i - 1][l]) {
        T[id].sum++;
        T[id].L[i] = T[id].R[i] = i;
      } else {
        T[id].L[i] = T[id].R[i] = T[id].L[i - 1];
      }
    }
    return;
  }
  int mid = (l + r) / 2;
  build(2 * id, l, mid);
  build(2 * id + 1, mid + 1, r);
  T[id] = _merge(T[2 * id], T[2 * id + 1]);
}
node query(int id, int l, int r) {
  if (T[id].l >= l && T[id].r <= r) return T[id];
  int mid = (T[id].l + T[id].r) / 2;
  if (l > mid) return query(2 * id + 1, l, r);
  if (r <= mid) return query(2 * id, l, r);
  return _merge(query(2 * id, l, mid), query(2 * id + 1, mid + 1, r));
}
int m, q, x, y;
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  }
  build(1, 1, m);
  while (q--) {
    scanf("%d%d", &x, &y);
    printf("%d\n", query(1, x, y).sum);
  }
  return 0;
}
