#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int v[10][N], col[10][N], lol, n, m, q;
int par[10 * N];
struct node {
  int sz, l, r;
  pair<int, int> lp[10], rp[10];
  node() {
    sz = 0;
    l = r = -1;
    for (int i = 0; i < 10; i++) lp[i] = rp[i] = {0, 0};
  }
} seg[4 * N];
int get(int u) { return par[u] == u ? u : par[u] = get(par[u]); }
node merge(const node &a, const node &b) {
  node ret;
  for (int i = 0; i < n; i++) {
    par[a.lp[i].first] = a.lp[i].second, par[a.lp[i].second] = a.lp[i].second;
    par[b.lp[i].first] = b.lp[i].second, par[b.lp[i].second] = b.lp[i].second;
    par[a.rp[i].first] = a.rp[i].second, par[a.rp[i].second] = a.rp[i].second;
    par[b.rp[i].first] = b.rp[i].second, par[b.rp[i].second] = b.rp[i].second;
  }
  ret.sz = a.sz + b.sz;
  for (int i = 0; i < n; i++) {
    int x = get(col[i][a.r]), y = get(col[i][b.l]);
    if (x == y || v[i][a.r] != v[i][b.l]) continue;
    par[x] = y;
    ret.sz--;
  }
  ret.l = a.l;
  ret.r = b.r;
  for (int i = 0; i < n; i++)
    ret.lp[i] = {a.lp[i].first, get(a.lp[i].first)},
    ret.rp[i] = {b.rp[i].first, get(b.rp[i].first)};
  return ret;
}
void build(int c, int l, int r) {
  if (l == r) {
    seg[c].l = seg[c].r = l;
    for (int i = 0; i < n; i++) par[col[i][l]] = col[i][l];
    for (int i = 0; i < n - 1; i++)
      if (v[i][l] == v[i + 1][l]) par[get(col[i + 1][l])] = get(col[i][l]);
    for (int i = 0; i < n; i++)
      seg[c].lp[i] = seg[c].rp[i] = {col[i][l], get(col[i][l])},
      seg[c].sz += col[i][l] == par[col[i][l]];
    return;
  }
  build(2 * c + 1, l, (l + r) / 2);
  build(2 * c + 2, (l + r) / 2 + 1, r);
  seg[c] = merge(seg[2 * c + 1], seg[2 * c + 2]);
}
node get(int c, int l, int r, int s, int e) {
  node ret;
  if (l >= s && r <= e) return seg[c];
  if ((l + r) / 2 >= e)
    ret = get(2 * c + 1, l, (l + r) / 2, s, e);
  else if ((l + r) / 2 < s)
    ret = get(2 * c + 2, (l + r) / 2 + 1, r, s, e);
  else
    ret = merge(get(2 * c + 1, l, (l + r) / 2, s, e),
                get(2 * c + 2, (l + r) / 2 + 1, r, s, e));
  return ret;
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &v[i][j]), col[i][j] = lol++;
  build(0, 0, m - 1);
  for (int i = 0; i < q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", get(0, 0, m - 1, --l, --r).sz);
  }
}
