#include <bits/stdc++.h>
using namespace std;
int n, m, q;
void rd(int &x) {
  char c;
  x = 0;
  while (c = getchar(), c < 48)
    ;
  do x = (x << 1) + (x << 3) + (c ^ 48);
  while (c = getchar(), c >= 48);
}
void pt(int x) {
  int s[10], t;
  for (t = 0; x; x /= 10) s[t++] = x % 10;
  while (t) putchar(s[--t] ^ 48);
  putchar('\n');
}
int fa[1000010];
int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }
int a[11][100010];
static const int N = 11, M = 100010;
struct Segment_Tree {
  struct Interval {
    int fal[N], far[N], sum, l, r;
    void re() {
      for (int i = 1; i <= n; i++) {
        fa[((i - 1) * m + l)] = fal[i], fa[((i - 1) * m + r)] = far[i];
        fa[fal[i]] = fal[i], fa[far[i]] = far[i];
      }
    }
    void getf() {
      for (int i = 1; i <= n; i++)
        fal[i] = get(((i - 1) * m + l)), far[i] = get(((i - 1) * m + r));
    }
    void init() {
      sum = n;
      for (int i = 1; i <= n; i++) {
        int t = ((i - 1) * m + l);
        if (a[i][l] == a[i - 1][l])
          fa[t] = fa[((i - 1 - 1) * m + l)], sum--;
        else
          fa[t] = t;
        fal[i] = far[i] = fa[t];
      }
    }
    friend Interval operator+(Interval A, Interval B) {
      Interval C;
      A.re(), B.re();
      C.l = A.l, C.r = B.r, C.sum = A.sum + B.sum;
      for (int i = 1; i <= n; i++) {
        if (a[i][A.r] != a[i][B.l]) continue;
        int p = get(((i - 1) * m + A.r)), q = get(((i - 1) * m + B.l));
        if (p != q) fa[p] = q, C.sum--;
      }
      C.getf();
      return C;
    }
  } g[M << 2];
  void build(int l, int r, int p) {
    g[p].l = l, g[p].r = r;
    if (l == r) {
      g[p].init();
      return;
    }
    int mid = (l + r) >> 1;
    build(l, mid, (p << 1));
    build(mid + 1, r, (p << 1 | 1));
    g[p] = g[(p << 1)] + g[(p << 1 | 1)];
  }
  Interval query(int l, int r, int p, int pl, int pr) {
    if (l == pl && r == pr) return g[p];
    int mid = (l + r) >> 1;
    if (pr <= mid)
      return query(l, mid, (p << 1), pl, pr);
    else if (pl > mid)
      return query(mid + 1, r, (p << 1 | 1), pl, pr);
    else
      return query(l, mid, (p << 1), pl, mid) +
             query(mid + 1, r, (p << 1 | 1), mid + 1, pr);
  }
} T;
void solve() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) rd(a[i][j]);
  T.build(1, m, 1);
  while (q--) {
    int l, r;
    rd(l), rd(r);
    pt(T.query(1, m, 1, l, r).sum);
  }
}
int main() {
  rd(n), rd(m), rd(q);
  solve();
  return 0;
}
