#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
}
inline void writeln(int x) {
  int w = 0, p[21];
  while (x) p[++w] = x % 10, x /= 10;
  while (w) putchar(p[w--] + '0');
  putchar('\n');
}
const int N = 1e5 + 5;
const int M = 1e6 + 5;
struct Node {
  int sum, l, r, fl[12], fr[12];
} tree[M];
int n, m, q, a[12][N], fa[M];
int root(int x) { return fa[x] == x ? x : fa[x] = root(fa[x]); }
Node merge(Node x, Node y) {
  Node res;
  res.l = x.l;
  res.r = y.r;
  res.sum = x.sum + y.sum;
  for (int i = 1; i <= n; i++) {
    fa[x.fl[i]] = x.fl[i];
    fa[x.fr[i]] = x.fr[i];
    fa[y.fl[i]] = y.fl[i];
    fa[y.fr[i]] = y.fr[i];
  }
  for (int i = 1; i <= n; i++)
    if (a[i][x.r] == a[i][y.l]) {
      int fx = root(x.fr[i]), fy = root(y.fl[i]);
      if (fx != fy) fa[fx] = fy, res.sum--;
    }
  for (int i = 1; i <= n; i++) {
    res.fl[i] = root(x.fl[i]);
    res.fr[i] = root(y.fr[i]);
  }
  return res;
}
void build(int now, int l, int r) {
  if (l == r) {
    tree[now].l = tree[now].r = r;
    tree[now].sum = 1;
    int num = (l - 1) * n;
    tree[now].fl[1] = tree[now].fr[1] = fa[num + 1] = num + 1;
    for (int i = 2; i <= n; i++)
      if (a[i][l] != a[i - 1][l]) {
        tree[now].fl[i] = tree[now].fr[i] = fa[num + i] = num + i;
        tree[now].sum++;
      } else
        tree[now].fl[i] = tree[now].fr[i] = fa[num + i] = root(num + i - 1);
    return;
  }
  int mid = (l + r) >> 1;
  build(now << 1, l, mid);
  build(now << 1 | 1, mid + 1, r);
  tree[now] = merge(tree[now << 1], tree[now << 1 | 1]);
}
Node query(int now, int l, int r, int x, int y) {
  if (x <= l && r <= y) return tree[now];
  int mid = (l + r) >> 1;
  if (x <= mid && y <= mid) return query(now << 1, l, mid, x, y);
  if (x > mid && y > mid) return query(now << 1 | 1, mid + 1, r, x, y);
  return merge(query(now << 1, l, mid, x, y),
               query(now << 1 | 1, mid + 1, r, x, y));
}
int main() {
  read(n);
  read(m);
  read(q);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) read(a[i][j]);
  build(1, 1, m);
  while (q--) {
    int a, b;
    read(a);
    read(b);
    writeln(query(1, 1, m, a, b).sum);
  }
  return 0;
}
