#include <bits/stdc++.h>
using namespace std;
const int maxn = 11;
const int maxm = 100050;
int n, m, q, cnt, fa[maxn * maxm * 8];
struct node {
  int lef[maxn], rig[maxn];
  int shit;
} t[maxm * 4];
int A[maxn][maxm];
void init(int a) { fa[a] = a; }
int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }
void merge(node a, node b, int mid, node &c) {
  for (int i = 1; i <= n; ++i) {
    init(a.lef[i]);
    init(a.rig[i]);
    init(b.lef[i]);
    init(b.rig[i]);
  }
  c.shit = a.shit + b.shit;
  for (int i = 1; i <= n; ++i)
    if (A[i][mid] == A[i][mid + 1]) {
      int x = getfa(a.rig[i]), y = getfa(b.lef[i]);
      if (x == y) continue;
      --c.shit;
      fa[x] = y;
    }
  for (int i = 1; i <= n; ++i)
    c.lef[i] = getfa(a.lef[i]), c.rig[i] = getfa(b.rig[i]);
}
node ask(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 ask(l, r, L, mid, k << 1);
  else if (l > mid)
    return ask(l, r, mid + 1, R, k << 1 | 1);
  else {
    node bullshit;
    merge(ask(l, mid, L, mid, k << 1), ask(mid + 1, r, mid + 1, R, k << 1 | 1),
          mid, bullshit);
    return bullshit;
  }
}
void build(int l, int r, int k) {
  if (l == r) {
    for (int i = 1; i <= n; ++i) {
      if (A[i][l] != A[i - 1][l]) {
        t[k].lef[i] = t[k].rig[i] = ++cnt;
        t[k].shit++;
      } else
        t[k].lef[i] = t[k].rig[i] = t[k].lef[i - 1];
    }
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, k << 1);
  build(mid + 1, r, k << 1 | 1);
  merge(t[k << 1], t[k << 1 | 1], mid, t[k]);
}
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, m, 1);
  for (int i = 1; i <= q; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", ask(l, r, 1, m, 1).shit);
  }
  return 0;
}
