#include <bits/stdc++.h>
using namespace std;
int a[11][100005];
struct node {
  int l[11], r[11];
  int L[11], R[11];
  int ans;
};
node st[400005];
int p[41], val[41];
int root(int a) { return p[a] == a ? a : (p[a] = root(p[a])); }
void merge(int a, int b) {
  a = root(a), b = root(b);
  if (a != b) p[a] = b;
}
int n, m, q;
node merge2(node a, node b) {
  if (a.ans == 0)
    return b;
  else if (b.ans == 0)
    return a;
  node ans;
  ans.ans = a.ans + b.ans;
  for (int i = 1; i <= 4 * n; i++) p[i] = i, val[i] = 0;
  for (int i = 1; i <= n; i++) {
    b.l[i] += 2 * n;
    b.r[i] += 2 * n;
  }
  for (int i = 1; i <= n; i++) {
    if (a.R[i] == b.L[i]) {
      ans.ans--;
      if (root(a.r[i]) == root(b.l[i])) ans.ans++;
      merge(a.r[i], b.l[i]);
    }
    ans.L[i] = a.L[i];
    ans.R[i] = b.R[i];
  }
  int cnt = 1;
  for (int i = 1; i <= n; i++) {
    ans.l[i] = a.l[i];
    ans.r[i] = b.r[i];
    if (val[root(ans.l[i])])
      ans.l[i] = val[root(ans.l[i])];
    else {
      val[root(ans.l[i])] = cnt++;
      ans.l[i] = val[root(ans.l[i])];
    }
    if (val[root(ans.r[i])])
      ans.r[i] = val[root(ans.r[i])];
    else {
      val[root(ans.r[i])] = cnt++;
      ans.r[i] = val[root(ans.r[i])];
    }
  }
  return ans;
}
void build(int N, int s, int e) {
  if (s == e) {
    for (int i = 1; i <= n; i++) {
      st[N].L[i] = a[i][s];
      st[N].R[i] = a[i][s];
    }
    int cnt = 1;
    for (int i = 1; i <= n; i++) {
      if (i == 1 || st[N].L[i] == st[N].L[i - 1]) {
        st[N].l[i] = cnt;
        st[N].r[i] = cnt;
      } else {
        cnt++;
        st[N].l[i] = cnt;
        st[N].r[i] = cnt;
      }
    }
    st[N].ans = cnt;
  } else {
    int mid = (s + e) / 2;
    build(N + N, s, mid);
    build(N + N + 1, mid + 1, e);
    st[N] = merge2(st[N + N], st[N + N + 1]);
  }
}
node query(int N, int s, int e, int l, int r) {
  if (s > r || l > e) {
    node ans;
    ans.ans = 0;
    return ans;
  }
  if (l <= s && e <= r) return st[N];
  int mid = (s + e) / 2;
  return merge2(query(N + N, s, mid, l, r), query(N + N + 1, mid + 1, e, l, r));
}
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);
  for (int i = 1; i <= q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", query(1, 1, m, l, r).ans);
  }
}
