#include <bits/stdc++.h>
using namespace std;
const int sz = 1e5 + 100;
struct _tree {
  int cnt, l[11], r[11];
};
_tree t[4 * sz];
int dsu[11 * sz], flag[11][sz];
int timer = 0, n, m;
int get(int v) {
  if (dsu[v] == v)
    return v;
  else
    return dsu[v] = get(dsu[v]);
}
int unite(int v, int u) {
  int a = get(v), b = get(u);
  if (a == b) return 0;
  if (rand() & 1)
    dsu[a] = b;
  else
    dsu[b] = a;
  return -1;
}
_tree mergetree(_tree a, _tree b, int mid) {
  _tree ans;
  ans.cnt = a.cnt + b.cnt;
  for (int i = 1; i <= n; i++) {
    dsu[a.l[i]] = a.l[i];
    dsu[a.r[i]] = a.r[i];
    dsu[b.l[i]] = b.l[i];
    dsu[b.r[i]] = b.r[i];
  }
  for (int i = 1; i <= n; i++)
    if (flag[i][mid] == flag[i][mid + 1]) ans.cnt += unite(a.r[i], b.l[i]);
  for (int i = 1; i <= n; i++) {
    ans.l[i] = get(a.l[i]);
    ans.r[i] = get(b.r[i]);
  }
  return ans;
}
void build(int v, int l, int r) {
  if (l == r) {
    for (int i = 1; i <= n; i++) {
      if (flag[i][l] != flag[i - 1][l]) {
        t[v].cnt++;
        t[v].l[i] = t[v].r[i] = timer++;
      } else
        t[v].l[i] = t[v].r[i] = t[v].l[i - 1];
    }
    return;
  }
  int mid = (l + r) >> 1, ls = v << 1, rs = ls | 1;
  build(ls, l, mid);
  build(rs, mid + 1, r);
  t[v] = mergetree(t[ls], t[rs], mid);
  return;
}
_tree query(int v, int l, int r, int ql, int qr) {
  if (l == ql && r == qr) return t[v];
  int mid = (l + r) >> 1, ls = v << 1, rs = ls | 1;
  if (qr <= mid) return query(ls, l, mid, ql, qr);
  if (ql > mid) return query(rs, mid + 1, r, ql, qr);
  return mergetree(query(ls, l, mid, ql, mid),
                   query(rs, mid + 1, r, mid + 1, qr), mid);
}
int main() {
  int q, i, j, l, r;
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> q;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> flag[i][j];
  build(1, 1, m);
  for (i = 0; i < q; i++) {
    cin >> l >> r;
    _tree cur = query(1, 1, m, l, r);
    cout << cur.cnt << endl;
  }
  return 0;
}
