#include <bits/stdc++.h>
using namespace std;
struct arr {
  int w[21], v;
} tmp, s[100006 << 2];
int n, m, q, l, r, f[41], a[21][100006], d[41];
inline int read() {
  int x = 0, c = getchar(), f = 1;
  while (c < '0' || c > '9') f = (c == '-' ? -f : f), c = getchar();
  while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - 48, c = getchar();
  return f > 0 ? x : -x;
}
void print(int x) {
  if (x > 9LL) print(x / 10LL);
  putchar(x % 10 + 48);
}
int get(int x) { return x == f[x] ? x : f[x] = get(f[x]); }
arr merge(arr x, arr y, int p) {
  tmp.v = x.v + y.v;
  int t = 0;
  for (int i = 1; i <= 4 * n; i++) f[i] = i, d[i] = 0;
  for (int i = 1; i <= n; i++)
    if (a[i][p] == a[i][p + 1]) {
      int c = get(x.w[n + i]), d = get(y.w[i] + 2 * n);
      c != d ? f[c] = d, tmp.v-- : 0;
    }
  for (int i = 1; i <= n; i++) {
    int c = get(x.w[i]);
    d[c] ? tmp.w[i] = d[c] : d[c] = tmp.w[i] = ++t;
  }
  for (int i = 1; i <= n; i++) {
    int c = get(y.w[i + n] + 2 * n);
    d[c] ? tmp.w[i + n] = d[c] : d[c] = tmp.w[i + n] = ++t;
  }
  return tmp;
}
void build(int i, int l, int r) {
  if (l == r) {
    int t = 0;
    for (int j = 1; j <= n; j++) {
      j == 1 || a[j][l] != a[j - 1][l] ? ++t : 0;
      s[i].w[j] = s[i].w[j + n] = t;
    }
    s[i].v = t;
    return;
  }
  build(i << 1, l, ((l + r) >> 1));
  build(i << 1 | 1, ((l + r) >> 1) + 1, r);
  s[i] = merge(s[i << 1], s[i << 1 | 1], ((l + r) >> 1));
}
arr ask(int i, int l, int r, int x, int y) {
  if (x <= l && r <= y) return s[i];
  if (y <= ((l + r) >> 1))
    return ask(i << 1, l, ((l + r) >> 1), x, y);
  else if (x > ((l + r) >> 1))
    return ask(i << 1 | 1, ((l + r) >> 1) + 1, r, x, y);
  else
    return merge(ask(i << 1, l, ((l + r) >> 1), x, y),
                 ask(i << 1 | 1, ((l + r) >> 1) + 1, r, x, y), ((l + r) >> 1));
}
int main() {
  n = read();
  m = read();
  q = read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) a[i][j] = read();
  build(1, 1, m);
  while (q--) {
    l = read(), r = read();
    print(ask(1, 1, m, l, r).v);
    puts("");
  }
}
