#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using pii = pair<int, int>;
struct info {
  int l[10], r[10], nr;
};
int m, n, cnt;
int a[10][100000];
info st[270000], nullinfo;
info join(info x, info y, int col) {
  if (x.nr == -1) return y;
  if (y.nr == -1) return x;
  info ret;
  ret.nr = x.nr + y.nr;
  for (int i = 0; i < m; ++i)
    if (a[i][col] == a[i][col + 1] && x.r[i] != y.l[i]) {
      --ret.nr;
      int old = x.r[i];
      for (int j = 0; j < m; ++j) {
        if (x.l[j] == old) x.l[j] = y.l[i];
        if (x.r[j] == old) x.r[j] = y.l[i];
        if (y.l[j] == old) y.l[j] = y.l[i];
        if (y.r[j] == old) y.r[j] = y.l[i];
      }
    }
  memcpy(ret.l, x.l, sizeof x.l);
  memcpy(ret.r, y.r, sizeof y.r);
  return ret;
}
void build_aint(int node, int l, int r) {
  if (l == r) {
    for (int i = 0; i < m; ++i)
      if (i > 0 && a[i - 1][l] == a[i][l])
        st[node].l[i] = st[node].r[i] = st[node].l[i - 1];
      else
        st[node].l[i] = st[node].r[i] = cnt++, st[node].nr++;
    return;
  }
  int mid = (l + r) / 2;
  build_aint(2 * node, l, mid);
  build_aint(2 * node + 1, mid + 1, r);
  st[node] = join(st[2 * node], st[2 * node + 1], mid);
}
info query(int node, int l, int r, int a, int b) {
  if (r < a) return nullinfo;
  if (l > b) return nullinfo;
  if (a <= l && r <= b) return st[node];
  int mid = (l + r) / 2;
  info x = query(2 * node, l, mid, a, b);
  info y = query(2 * node + 1, mid + 1, r, a, b);
  return join(x, y, mid);
}
int main() {
  ios_base::sync_with_stdio(false);
  int i, j, q, l, r;
  nullinfo.nr = -1;
  cin >> m >> n >> q;
  for (i = 0; i < m; ++i)
    for (j = 0; j < n; ++j) cin >> a[i][j];
  build_aint(1, 0, n - 1);
  for (; q; --q) {
    cin >> l >> r;
    auto ret = query(1, 0, n - 1, l - 1, r - 1);
    cout << ret.nr << '\n';
  }
  return 0;
}
