#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXM = 1 << 18;
const int MAXN = 11;
int par[MAXM * 10], cnt;
int find_root(int x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = find_root(par[x]);
}
void unite(int x, int y) {
  x = find_root(x), y = find_root(y);
  if (x == y) return;
  par[x] = y;
}
struct Node {
  int L[MAXN], R[MAXN];
  int C;
} ST[MAXM];
int n, m;
int flag[MAXN][MAXM];
Node Merge(Node a, Node b, int l, int m, int r) {
  if (a.C == 0) return b;
  if (b.C == 0) return a;
  Node res;
  res.C = a.C + b.C;
  for (int i = (0); i < (n); i++)
    par[a.R[i]] = a.R[i], par[a.L[i]] = a.L[i], par[b.L[i]] = b.L[i],
    par[b.R[i]] = b.R[i];
  for (int i = (0); i < (n); i++) {
    if (flag[i][m - 1] == flag[i][m]) {
      if (find_root(a.R[i]) != find_root(b.L[i])) res.C--;
      unite(a.R[i], b.L[i]);
    }
  }
  for (int i = (0); i < (n); i++)
    res.R[i] = find_root(b.R[i]), res.L[i] = find_root(a.L[i]);
  return res;
}
void build(int k, int l, int r) {
  if (r - l == 0) return;
  if (r - l == 1) {
    for (int i = (0); i < (n); i++) ST[k].L[i] = cnt++;
    for (int i = (0); i < (n); i++) par[ST[k].L[i]] = ST[k].L[i];
    for (int i = (1); i < (n); i++) {
      if (flag[i - 1][l] == flag[i][l]) unite(ST[k].L[i], ST[k].L[i - 1]);
    }
    for (int i = (0); i < (n); i++) {
      if (ST[k].L[i] == find_root(ST[k].L[i])) ST[k].C++;
      ST[k].L[i] = ST[k].R[i] = find_root(ST[k].L[i]);
    }
    return;
  }
  int m = l + r >> 1;
  build((k << 1), l, m);
  build((k << 1 | 1), m, r);
  ST[k] = Merge(ST[(k << 1)], ST[(k << 1 | 1)], l, m, r);
}
Node query(int k, int l, int r, int ql, int qr) {
  if (ql >= r || qr <= l) {
    Node res;
    res.C = 0;
    return res;
  }
  if (ql <= l && r <= qr) return ST[k];
  int m = l + r >> 1;
  return Merge(query((k << 1), l, m, ql, qr), query((k << 1 | 1), m, r, ql, qr),
               l, m, r);
}
int main() {
  int q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = (0); i < (n); i++)
    for (int j = (1); j < (m + 1); j++) scanf("%d", &flag[i][j]);
  build(1, 1, m + 1);
  for (int i = (0); i < (q); i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    Node Q = query(1, 1, m + 1, l, r + 1);
    printf("%d\n", Q.C);
  }
}
