#include <bits/stdc++.h>
using namespace std;
const int N = 11, M = 100100;
int i, j, k, n, m, q, ch, l, r;
int A[M][N];
int fa[N << 2], z[N << 2];
int getf(int x) {
  if (fa[x] == x) return x;
  return fa[x] = getf(fa[x]);
}
void R(int &x) {
  x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch) ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
}
struct tree {
  int L, R, sum, f[N << 1];
  tree operator+(const tree &nt) const {
    tree a;
    a.L = L;
    a.R = nt.R;
    a.sum = sum + nt.sum;
    int i, nm = 0;
    for (i = 1; i <= n + n; i++) fa[++nm] = f[i];
    for (i = 1; i <= n + n; i++) fa[++nm] = nt.f[i] + n + n;
    for (i = 1; i <= n; i++)
      if (A[R][i] == A[nt.L][i] && getf(n + i) != getf(n + n + i)) {
        a.sum--;
        fa[fa[n + i]] = fa[n + n + i];
      }
    for (i = 1; i <= nm; i++) z[i] = 0;
    for (i = 1; i <= n; i++) {
      if (!z[getf(i)])
        a.f[i] = i, z[fa[i]] = i;
      else
        a.f[i] = z[fa[i]];
    }
    for (i = n + n + n + 1; i <= nm; i++) {
      if (!z[getf(i)])
        a.f[i - n - n] = i - n - n, z[fa[i]] = i - n - n;
      else
        a.f[i - n - n] = z[fa[i]];
    }
    return a;
  }
} T[M << 2];
void T_build(int L, int R, int k) {
  if (L == R) {
    T[k].L = T[k].R = L;
    for (int i = 1; i <= n; i++) {
      if (A[L][i] != A[L][i - 1])
        T[k].sum++, T[k].f[i] = i;
      else
        T[k].f[i] = T[k].f[i - 1];
    }
    for (int i = n + 1; i <= n + n; i++) T[k].f[i] = T[k].f[i - n];
    return;
  }
  int mid = (L + R) >> 1;
  T_build(L, mid, k << 1);
  T_build(mid + 1, R, k << 1 | 1);
  T[k] = T[k << 1] + T[k << 1 | 1];
}
tree T_query(int L, int R, int l, int r, int k) {
  if (L == l && R == r) return T[k];
  int mid = (L + R) >> 1;
  if (r <= mid) return T_query(L, mid, l, r, k << 1);
  if (l > mid) return T_query(mid + 1, R, l, r, k << 1 | 1);
  return T_query(L, mid, l, mid, k << 1) +
         T_query(mid + 1, R, mid + 1, r, k << 1 | 1);
}
int main() {
  R(n);
  R(m);
  R(q);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) R(A[j][i]);
  T_build(1, m, 1);
  for (i = 1; i <= q; i++) {
    R(l);
    R(r);
    printf("%d\n", T_query(1, m, l, r, 1).sum);
  }
}
