#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int h, w, q, a[12][N], p[40], cnt[40];
int group(int a) { return (p[a] == -1) ? a : p[a] = group(p[a]); }
struct info {
  int x, y, pl[10], pr[10], cnt;
  info() { cnt = -1; }
  info(int _x) {
    x = y = _x;
    cnt = 1;
    for (int i = (0); i < (h); i++) {
      if (i && a[i][x] != a[i - 1][x]) cnt++;
      pl[i] = pr[i] = cnt - 1;
    }
  }
};
info unite(const info& l, const info& r) {
  if (l.cnt == -1) return r;
  if (r.cnt == -1) return l;
  info res;
  res.x = l.x;
  res.y = r.y;
  res.cnt = l.cnt + r.cnt;
  for (int i = (0); i < (4 * h); i++) {
    cnt[i] = 0;
    p[i] = -1;
  }
  int c = l.y;
  for (int i = (0); i < (h); i++)
    if (a[i][c] == a[i][c + 1]) {
      int x = group(l.pr[i]);
      int y = group(r.pl[i] + 2 * h);
      if (x == y) continue;
      res.cnt--;
      p[x] = y;
    }
  for (int i = (0); i < (h); i++) {
    cnt[group(l.pl[i])] = 1;
    cnt[group(r.pr[i] + 2 * h)] = 1;
  }
  for (int i = (1); i < (4 * h); i++) cnt[i] += cnt[i - 1];
  for (int i = (0); i < (h); i++) {
    res.pl[i] = cnt[group(l.pl[i])] - 1;
    res.pr[i] = cnt[group(r.pr[i] + 2 * h)] - 1;
  }
  return res;
}
struct node;
typedef node* np;
struct node {
  int sz;
  np l, r;
  info z;
  node(int _sz, int off) {
    sz = _sz;
    if (sz == 1) {
      z = info(off);
      return;
    }
    l = new node(sz / 2, off);
    r = new node(sz - sz / 2, off + sz / 2);
    z = unite(l->z, r->z);
  }
  info get(int a, int b) {
    if (b <= 0 || sz <= a) return info();
    if (a <= 0 && sz <= b) return z;
    return unite(l->get(a, b), r->get(a - sz / 2, b - sz / 2));
  }
};
int main() {
  scanf("%d%d%d", &h, &w, &q);
  for (int i = (0); i < (h); i++)
    for (int j = (0); j < (w); j++) scanf("%d", &a[i][j]);
  np tr = new node(w, 0);
  for (int i = (0); i < (q); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    info res = tr->get(x, y);
    printf("%d\n", res.cnt);
  }
}
