#include <bits/stdc++.h>
using namespace std;
const int NMAX = 12, MMAX = 210000, TMAX = 410000;
struct Node {
  int cnt;
  int com[2][NMAX];
  int table[2][NMAX];
};
int N, M, Q, L, TL;
int table[NMAX][MMAX];
Node T[TMAX];
int Find(int fa[], int x) {
  int pa, tmp;
  for (pa = x; fa[pa] >= 0; pa = fa[pa])
    ;
  while (x != pa) {
    tmp = fa[x];
    fa[x] = pa;
    x = tmp;
  }
  return pa;
}
void Union(int fa[], int x, int y) {
  int X = Find(fa, x), Y = Find(fa, y);
  if (X == Y) return;
  if (fa[X] > fa[Y]) swap(X, Y);
  fa[X] += fa[Y];
  fa[Y] = X;
}
Node Merge(const Node &x, const Node &y) {
  int i, pa, cnt = 0, fa[4 * NMAX], id[4 * NMAX];
  Node res;
  memset(fa, -1, sizeof(fa));
  memset(id, -1, sizeof(id));
  res.cnt = x.cnt + y.cnt;
  for (i = 1; i <= N; i += 1) {
    if (x.table[1][i] == y.table[0][i])
      Union(fa, x.com[1][i], 2 * N + y.com[0][i]);
    res.table[0][i] = x.table[0][i];
    res.table[1][i] = y.table[1][i];
  }
  for (i = 1; i <= N; i += 1) {
    pa = Find(fa, x.com[0][i]);
    if (id[pa] < 0) id[pa] = ++cnt;
    res.com[0][i] = id[pa];
  }
  for (i = 1; i <= N; i += 1) {
    pa = Find(fa, 2 * N + y.com[1][i]);
    if (id[pa] < 0) id[pa] = ++cnt;
    res.com[1][i] = id[pa];
  }
  for (i = 1; i <= 4 * N; i += 1) {
    if (fa[i] < 0) res.cnt += fa[i] + 1;
  }
  return res;
}
void build() {
  int i, j;
  for (i = 1; i <= L; i += 1) {
    for (j = 1; j <= N; j += 1) {
      if (j == 1 || table[j][i] != table[j - 1][i]) T[L + i - 1].cnt += 1;
      T[L + i - 1].com[0][j] = T[L + i - 1].com[1][j] = T[L + i - 1].cnt;
      T[L + i - 1].table[0][j] = T[L + i - 1].table[1][j] = table[j][i];
    }
  }
  for (i = L - 1; i; i -= 1) T[i] = Merge(T[2 * i], T[2 * i + 1]);
}
Node query(int pos, int l, int r, int p, int q) {
  int mid = (l + r) >> 1;
  bool lFlag = false, rFlag = false;
  Node res1, res2;
  if (l == p && r == q) return T[pos];
  if (p <= mid) {
    lFlag = true;
    res1 = query(2 * pos, l, mid, p, min(mid, q));
  }
  if (mid < q) {
    rFlag = true;
    res2 = query(2 * pos + 1, mid + 1, r, max(mid + 1, p), q);
  }
  if (lFlag && rFlag)
    return Merge(res1, res2);
  else if (lFlag)
    return res1;
  else
    return res2;
}
int main() {
  int i, j, l, r;
  scanf("%d %d %d", &N, &M, &Q);
  for (i = 1; i <= N; i += 1) {
    for (j = 1; j <= M; j += 1) scanf("%d", &table[i][j]);
  }
  for (L = 1; L < M; L <<= 1)
    ;
  TL = 2 * L - 1;
  build();
  for (i = 1; i <= Q; i += 1) {
    scanf("%d %d", &l, &r);
    printf("%d\n", query(1, 1, L, l, r).cnt);
  }
  exit(0);
}
