#include <bits/stdc++.h>
using namespace std;
const int MAX = (1e5) + 1;
int n, m, q, a[11][MAX];
struct node {
  int cnt, l, r;
  vector<int> f;
};
node t[4 * MAX];
int root(int v, vector<int>& dsu) {
  return (dsu[v] == v ? v : dsu[v] = root(dsu[v], dsu));
}
void init(node& x, int col) {
  x.l = x.r = col;
  x.cnt = n;
  x.f.resize(2 * n);
  iota(x.f.begin(), x.f.begin() + n, 0);
  for (int i = 1; i < n; i++)
    if (a[i][col] == a[i - 1][col]) {
      int u = root(i - 1, x.f), v = root(i, x.f);
      x.f[v] = x.f[u];
      x.cnt--;
    }
  for (int i = n; i < 2 * n; i++) x.f[i] = x.f[i - n];
}
node merge(node& x, node& y) {
  int cnt = 0;
  vector<int> tmp(4 * n);
  iota(tmp.begin(), tmp.end(), 0);
  for (int i = 0; i < 2 * n; i++) tmp[i] = x.f[i];
  for (int i = 0; i < 2 * n; i++) tmp[2 * n + i] = y.f[i] + 2 * n;
  for (int i = 0; i < n; i++)
    if (a[i][x.r] == a[i][y.l] && root(i + n, tmp) != root(i + 2 * n, tmp)) {
      cnt++;
      int u = root(i + n, tmp), v = root(i + 2 * n, tmp);
      tmp[v] = u;
    }
  vector<int> mp = tmp;
  for (int i = 0; i < n; i++) mp[root(i, tmp)] = i;
  for (int i = 3 * n; i < 4 * n; i++) mp[root(i, tmp)] = i - 2 * n;
  vector<int> ret(2 * n);
  for (int i = 0; i < n; i++) ret[i] = mp[root(i, tmp)];
  for (int i = 3 * n; i < 4 * n; i++) ret[i - 2 * n] = mp[root(i, tmp)];
  return {x.cnt + y.cnt - cnt, x.l, y.r, ret};
}
void build(int pos, int l, int r) {
  if (l == r)
    init(t[pos], l);
  else {
    int mid = l + r >> 1;
    build(pos * 2, l, mid);
    build(pos * 2 + 1, mid + 1, r);
    t[pos] = merge(t[pos * 2], t[pos * 2 + 1]);
  }
}
node query(int pos, int l, int r) {
  if (t[pos].l >= l && t[pos].r <= r) return t[pos];
  if (t[2 * pos].r < l || t[2 * pos].l > r) return query(2 * pos + 1, l, r);
  if (t[2 * pos + 1].r < l || t[2 * pos + 1].l > r) return query(2 * pos, l, r);
  node x = query(2 * pos, l, r);
  node y = query(2 * pos + 1, l, r);
  return merge(x, y);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> a[i][j], a[i][j]--;
  }
  build(1, 0, m - 1);
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << query(1, l - 1, r - 1).cnt << '\n';
  }
}
