#include <bits/stdc++.h>
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 500000;
using namespace std;
int t[MAXN], lt[13][MAXN], rt[13][MAXN], a[13][MAXN], n, m, p[1500000], now,
    have[MAXN];
int get(int x) {
  if (p[x] != x) p[x] = get(p[x]);
  return p[x];
}
void build(int v, int tl, int tr) {
  if (tl == tr) {
    for (int i = 1; i <= n; i++)
      if (a[i - 1][tl] != a[i][tl]) {
        ++t[v], rt[i][v] = lt[i][v] = i * m - m + tl;
      } else
        lt[i][v] = rt[i][v] = rt[i - 1][v];
  } else {
    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm);
    build(v * 2 + 1, tm + 1, tr);
    t[v] = t[v * 2] + t[v * 2 + 1];
    for (int i = 1; i <= n; i++)
      p[rt[i][v * 2]] = rt[i][v * 2], p[lt[i][v * 2 + 1]] = lt[i][v * 2 + 1],
                  p[rt[i][v * 2 + 1]] = rt[i][v * 2 + 1],
                  p[lt[i][v * 2]] = lt[i][v * 2];
    for (int i = 1; i <= n; i++)
      if (a[i][tm] == a[i][tm + 1] &&
          get(rt[i][v * 2]) != get(lt[i][v * 2 + 1]))
        --t[v], p[get(rt[i][v * 2])] = get(lt[i][v * 2 + 1]);
    for (int i = 1; i <= n; i++)
      lt[i][v] = get(lt[i][v * 2]), rt[i][v] = get(rt[i][v * 2 + 1]);
  }
}
int get(int v, int tl, int tr, int l, int r) {
  if (tl == l && tr == r) {
    int x = 0;
    if (now) {
      for (int i = 1; i <= n; i++)
        p[rt[i][v]] = rt[i][v], p[lt[i][v]] = lt[i][v], p[have[i]] = have[i];
      for (int i = 1; i <= n; i++)
        if (a[i][tl - 1] == a[i][tl] && get(have[i]) != get(lt[i][v]))
          ++x, p[get(lt[i][v])] = get(have[i]);
      for (int i = 1; i <= n; i++) have[i] = get(rt[i][v]);
    } else {
      for (int i = 1; i <= n; i++) have[i] = rt[i][v];
    }
    now = v;
    return t[v] - x;
  }
  if (l > r) return 0;
  int tm = (tl + tr) / 2;
  int x = get(v * 2, tl, tm, l, min(r, tm));
  return x + get(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(time(0));
  int q, i, j;
  cin >> n >> m >> q;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> a[i][j];
  build(1, 1, m);
  for (i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    now = 0;
    cout << get(1, 1, m, l, r) << endl;
  }
  return 0;
}
