#include <bits/stdc++.h>
const int N = 100005;
using namespace std;
int L[N * 4][12], R[N * 4][12], sum[N * 4], cnt = 0;
int fa[N * 10], a[12][N], n, m, q;
int rrs[12], ans;
bool flag;
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void update(int rt, int l, int r) {
  int mid = (l + r) >> 1;
  int ls = rt << 1, rs = rt << 1 | 1;
  sum[rt] = sum[ls] + sum[rs];
  for (int i = 1; i <= n; i++) {
    fa[L[ls][i]] = L[ls][i];
    fa[L[rs][i]] = L[rs][i];
    fa[R[ls][i]] = R[ls][i];
    fa[R[rs][i]] = R[rs][i];
  }
  for (int i = 1; i <= n; i++) {
    if (a[i][mid] == a[i][mid + 1]) {
      int x = find(R[ls][i]), y = find(L[rs][i]);
      if (x != y) {
        sum[rt]--;
        fa[y] = x;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    L[rt][i] = find(L[ls][i]);
    R[rt][i] = find(R[rs][i]);
  }
}
void build(int rt, int l, int r) {
  if (l == r) {
    for (int i = 1; i <= n; i++)
      if (a[i][l] == a[i - 1][l])
        L[rt][i] = R[rt][i] = L[rt][i - 1];
      else
        L[rt][i] = R[rt][i] = ++cnt, sum[rt]++;
    return;
  }
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  update(rt, l, r);
}
void query(int rt, int l, int r, int ll, int rr) {
  if (l >= ll && r <= rr) {
    if (!flag) {
      flag = true;
      ans = sum[rt];
      for (int i = 1; i <= n; i++) rrs[i] = R[rt][i];
    } else {
      ans += sum[rt];
      for (int i = 1; i <= n; i++) {
        fa[rrs[i]] = rrs[i];
        fa[L[rt][i]] = L[rt][i];
        fa[R[rt][i]] = R[rt][i];
      }
      for (int i = 1; i <= n; i++) {
        if (a[i][l] == a[i][l - 1]) {
          int x = find(rrs[i]), y = find(L[rt][i]);
          if (x != y) {
            ans--;
            fa[x] = y;
          }
        }
      }
      for (int i = 1; i <= n; i++) rrs[i] = find(R[rt][i]);
    }
    return;
  }
  int mid = (l + r) >> 1;
  if (ll <= mid) query(rt << 1, l, mid, ll, rr);
  if (rr > mid) query(rt << 1 | 1, mid + 1, r, ll, rr);
}
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);
    flag = 0;
    ans = 0;
    query(1, 1, m, l, r);
    printf("%d\n", ans);
  }
  return 0;
}
