#include <bits/stdc++.h>
using namespace std;
struct block {
  int num, l[11], r[11], f[22];
};
int n, m, q, l, r, a[11][110000], p[50], fa[50];
block ans;
int find(int x) {
  if (fa[x] == x) return x;
  fa[x] = find(fa[x]);
  return fa[x];
}
int merge(int u, int v) {
  int fv = find(v), fu = find(u);
  if (fv == fu) return 0;
  fa[fv] = fu;
  return 1;
}
block combine(const block &a, const block &b) {
  block c;
  c.num = a.num + b.num;
  memset(p, 0, sizeof(p));
  for (int i = 1; i <= 2 * n; i++) {
    fa[i] = a.f[i];
    fa[i + 2 * n] = b.f[i] + 2 * n;
  }
  for (int i = 1; i <= n; i++) {
    c.l[i] = a.l[i];
    c.r[i] = b.r[i];
    if (a.r[i] == b.l[i]) c.num -= merge(i + n, i + 2 * n);
  }
  for (int i = 1; i <= n; i++) {
    int u = find(i);
    if (!p[u]) p[u] = i;
    c.f[i] = p[u];
    u = find(3 * n + i);
    if (!p[u]) p[u] = n + i;
    c.f[i + n] = p[u];
  }
  return c;
}
struct segment_tree {
  struct node {
    int l, r;
    block b;
  } t[4 * 110000];
  void update(int x) { t[x].b = combine(t[x * 2].b, t[x * 2 + 1].b); }
  void build(int x, int l, int r) {
    t[x].l = l;
    t[x].r = r;
    if (l == r) {
      block &w = t[x].b;
      w.num = n;
      for (int i = 1; i <= 2 * n; i++) w.f[i] = i;
      for (int i = 1; i <= n; i++) {
        w.f[i] = n + i;
        if (i < n && a[i][l] == a[i + 1][l]) {
          w.f[i + n] = n + i + 1;
          w.num--;
        }
        w.l[i] = w.r[i] = a[i][l];
      }
      return;
    }
    int mid = (l + r) / 2;
    build(x * 2, l, mid);
    build(x * 2 + 1, mid + 1, r);
    update(x);
  }
  void ask(int x, int l, int r) {
    if (t[x].r < l || t[x].l > r) return;
    if (l <= t[x].l && t[x].r <= r) {
      if (ans.num == 0)
        ans = t[x].b;
      else
        ans = combine(ans, t[x].b);
      return;
    }
    ask(x * 2, l, r);
    ask(x * 2 + 1, l, r);
  }
} T;
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]);
  T.build(1, 1, m);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &l, &r);
    ans.num = 0;
    T.ask(1, l, r);
    printf("%d\n", ans.num);
  }
  return 0;
}
