#include <bits/stdc++.h>
using namespace std;
const int MX = 100010;
inline char get(void) {
  static char buf[100000], *p1 = buf, *p2 = buf;
  if (p1 == p2) {
    p2 = (p1 = buf) + fread(buf, 1, 100000, stdin);
    if (p1 == p2) return EOF;
  }
  return *p1++;
}
inline void read(int &x) {
  x = 0;
  static char c;
  for (; !(c >= '0' && c <= '9'); c = get())
    ;
  for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = get())
    ;
}
int fa[50], id[50];
inline int getf(int x) { return x == fa[x] ? x : (fa[x] = getf(fa[x])); }
inline int Union(int x, int y) {
  x = getf(x), y = getf(y);
  if (x != y) return fa[x] = y, 1;
  return 0;
}
int N, M, Q, A[11][MX];
struct Node {
  int l[11], r[11], sum;
} O[MX << 2];
Node pushUp(Node a, Node b, int pos) {
  static Node t;
  for (int i = 1; i <= 4 * N + 1; i++) fa[i] = i;
  t.sum = a.sum + b.sum;
  for (int i = 1; i <= N; i++)
    if (A[i][pos] == A[i][pos + 1]) t.sum -= Union(a.r[i], b.l[i] + N * 2);
  memset(id, 0, sizeof id);
  int cnt = 0;
  for (int i = 1; i <= N; i++) {
    int &u = id[getf(a.l[i])];
    if (!u) u = ++cnt;
    t.l[i] = u;
  }
  for (int i = 1; i <= N; i++) {
    int &u = id[getf(b.r[i] + N * 2)];
    if (!u) u = ++cnt;
    t.r[i] = u;
  }
  return t;
}
inline void build(int o, int l, int r) {
  if (l == r) {
    int t = 0;
    for (int i = 1; i <= N; i++) {
      if (i == 1 || A[i][l] != A[i - 1][l]) t++;
      O[o].l[i] = O[o].r[i] = t;
    }
    O[o].sum = t;
    return;
  }
  int mid = (l + r) >> 1;
  build(o << 1, l, mid), build(o << 1 | 1, mid + 1, r);
  O[o] = pushUp(O[o << 1], O[o << 1 | 1], mid);
}
inline Node Query(int o, int l, int r, int L, int R) {
  if (l == L && r == R) return O[o];
  int mid = (l + r) >> 1;
  if (R <= mid)
    return Query(o << 1, l, mid, L, R);
  else if (L > mid)
    return Query(o << 1 | 1, mid + 1, r, L, R);
  else
    return pushUp(Query(o << 1, l, mid, L, mid),
                  Query(o << 1 | 1, mid + 1, r, mid + 1, R), mid);
}
int main(void) {
  read(N), read(M), read(Q);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) read(A[i][j]);
  int L, R;
  build(1, 1, M);
  while (Q--) {
    read(L), read(R);
    printf("%d\n", Query(1, 1, M, L, R).sum);
  }
  return 0;
}
