#include <bits/stdc++.h>
using namespace std;
inline int Read() {
  int e = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while ('0' <= ch && ch <= '9') e = e * 10 + (ch - '0'), ch = getchar();
  return e;
}
const int maxn = 1e5 + 7;
struct node {
  int l, r, sum;
  int rcdl[11], rcdr[11];
} tree[maxn << 2], ans;
int a[11][maxn], n, m, q, pre[maxn << 4], cnt = 0;
int Find_set(int key) {
  if (pre[key] != key) pre[key] = Find_set(pre[key]);
  return pre[key];
}
node Merge(node p, node q) {
  node ovo;
  ovo.l = p.l;
  ovo.r = q.r;
  ovo.sum = p.sum + q.sum;
  for (int i = 1; i <= n; i++) {
    pre[p.rcdl[i]] = p.rcdl[i];
    pre[p.rcdr[i]] = p.rcdr[i];
    pre[q.rcdl[i]] = q.rcdl[i];
    pre[q.rcdr[i]] = q.rcdr[i];
  }
  for (int i = 1; i <= n; i++) {
    if (a[i][p.r] != a[i][q.l]) continue;
    int u = Find_set(p.rcdr[i]), v = Find_set(q.rcdl[i]);
    if (u == v) continue;
    ovo.sum--;
    pre[v] = u;
  }
  for (int i = 1; i <= n; i++)
    ovo.rcdl[i] = Find_set(p.rcdl[i]), ovo.rcdr[i] = Find_set(q.rcdr[i]);
  return ovo;
}
void Buildtree(int l, int r, int key) {
  if (l == r) {
    tree[key].l = tree[key].r = l;
    int tmp = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i][l] != a[i - 1][l]) {
        tree[key].rcdl[i] = tree[key].rcdr[i] = ++cnt;
        tmp++;
      } else
        tree[key].rcdl[i] = tree[key].rcdr[i] = tree[key].rcdl[i - 1];
    }
    tree[key].sum = tmp;
    return;
  }
  int mid = (l + r) >> 1;
  Buildtree(l, mid, key << 1);
  Buildtree(mid + 1, r, key << 1 | 1);
  tree[key] = Merge(tree[key << 1], tree[key << 1 | 1]);
}
node Query(int l, int r, int key) {
  if (l == tree[key].l && tree[key].r == r) return tree[key];
  int mid = (tree[key].l + tree[key].r) >> 1;
  if (r <= mid)
    return Query(l, r, key << 1);
  else if (mid < l)
    return Query(l, r, key << 1 | 1);
  else
    return Merge(Query(l, mid, key << 1), Query(mid + 1, r, key << 1 | 1));
}
int main() {
  n = Read(), m = Read(), q = Read();
  memset(a, -1, sizeof(a));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) a[i][j] = Read();
  Buildtree(1, m, 1);
  while (q--) {
    int x = Read();
    int y = Read();
    ans = Query(x, y, 1);
    printf("%d\n", ans.sum);
  }
  return 0;
}
