#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, A[12][N], q;
struct node {
  int ans, lrt[12], rrt[12];
  void trans(int u, int v) {
    ans--;
    for (int i = 1; i <= n; i++) {
      if (lrt[i] == u) lrt[i] = v;
      if (rrt[i] == u) rrt[i] = v;
    }
  }
} t[N << 2];
node _merge(node a, node b, int l, int r) {
  node ret;
  ret.ans = a.ans + b.ans;
  for (int i = 1; i <= n; i++) ret.lrt[i] = a.lrt[i], ret.rrt[i] = b.rrt[i];
  for (int i = 1; i <= n; i++) {
    if (A[i][l] == A[i][r] && a.rrt[i] != b.lrt[i]) {
      ret.trans(a.rrt[i], b.lrt[i]);
      a.trans(a.rrt[i], b.lrt[i]);
    }
  }
  return ret;
}
void build(int u, int l, int r) {
  if (l == r) {
    t[u].ans = n;
    for (int i = 1; i <= n; i++) t[u].lrt[i] = t[u].rrt[i] = (l - 1) * n + i;
    for (int i = 1; i <= n; i++)
      if (A[i][l] == A[i - 1][l]) t[u].trans(t[u].lrt[i], t[u].lrt[i - 1]);
    return;
  }
  int mid = (l + r) / 2;
  build(u << 1, l, mid);
  build(u << 1 | 1, mid + 1, r);
  t[u] = _merge(t[u << 1], t[u << 1 | 1], mid, mid + 1);
}
node query(int u, int l, int r, int L, int R) {
  if (l == L && r == R) return t[u];
  int mid = (l + r) / 2;
  if (R <= mid)
    return query(u << 1, l, mid, L, R);
  else if (L > mid)
    return query(u << 1 | 1, mid + 1, r, L, R);
  else
    return _merge(query(u << 1, l, mid, L, mid),
                  query(u << 1 | 1, mid + 1, r, mid + 1, R), mid, mid + 1);
}
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--) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", query(1, 1, m, l, r).ans);
  }
  return 0;
}
