#include <bits/stdc++.h>
inline int read() {
  int x;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  for (x = c - '0'; (c = getchar()) >= '0' && c <= '9';)
    x = (x << 3) + (x << 1) + c - '0';
  return x;
}
int n, a[10 + 5][100000 + 5], f[100000 + 5], u[45];
int gf(int k) { return f[k] ? f[k] = gf(f[k]) : k; }
struct data {
  int lk[10 + 5], rk[10 + 5], lc[10 + 5], rc[10 + 5], s;
  friend data operator+(const data& a, const data& b) {
    int i, cnt = 0;
    data c;
    c.s = a.s + b.s;
    for (i = 1; i <= n; ++i)
      f[a.lk[i]] = f[a.rk[i]] = f[b.lk[i] + 20] = f[b.rk[i] + 20] = 0;
    for (i = 1; i <= n; ++i)
      if (a.rc[i] == b.lc[i])
        if (gf(a.rk[i]) != gf(b.lk[i] + 20))
          f[gf(a.rk[i])] = gf(b.lk[i] + 20), --c.s;
    for (i = 1; i <= n; ++i) c.lk[i] = gf(a.lk[i]), c.rk[i] = gf(b.rk[i] + 20);
    memset(u, 0, sizeof(u));
    for (i = 1; i <= n; ++i) {
      if (!u[c.lk[i]]) u[c.lk[i]] = ++cnt;
      c.lk[i] = u[c.lk[i]];
      c.lc[i] = a.lc[i];
      if (!u[c.rk[i]]) u[c.rk[i]] = ++cnt;
      c.rk[i] = u[c.rk[i]];
      c.rc[i] = b.rc[i];
    }
    return c;
  }
};
struct node {
  int l, r;
  data x;
} t[100000 * 4 + 5];
void build(int k, int l, int r) {
  if ((t[k].l = l) == (t[k].r = r)) {
    int i, j;
    for (i = 1; i <= n; i = j) {
      ++t[k].x.s;
      for (j = i; j <= n && a[i][l] == a[j][l]; ++j)
        t[k].x.lk[j] = t[k].x.rk[j] = t[k].x.s,
        t[k].x.lc[j] = t[k].x.rc[j] = a[j][l];
    }
    return;
  }
  int mid = l + r >> 1;
  build((k << 1), l, mid);
  build((k << 1 | 1), mid + 1, r);
  t[k].x = t[(k << 1)].x + t[(k << 1 | 1)].x;
}
data query(int k, int l, int r) {
  if (t[k].l == l && t[k].r == r) return t[k].x;
  int mid = t[k].l + t[k].r >> 1;
  if (r <= mid) return query((k << 1), l, r);
  if (l > mid) return query((k << 1 | 1), l, r);
  return query((k << 1), l, mid) + query((k << 1 | 1), mid + 1, r);
}
int main() {
  int m, q, i, j;
  n = read();
  m = read();
  q = read();
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) a[i][j] = read();
  build(1, 1, m);
  while (q--) i = read(), j = read(), printf("%d\n", query(1, i, j).s);
}
