#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 8;
const int M = 20;
struct node {
  int sum;
  int a[M];
  int b[M];
} T[N << 2];
int a[M][N];
int f[N], id[N];
int n, m, q;
int find(int x) {
  if (f[x] == x) return x;
  return f[x] = find(f[x]);
}
void merge(node &rt, node &l, node &r, int lpos, int rpos) {
  rt.sum = l.sum + r.sum;
  for (int i = 0; i < m; ++i) {
    f[i] = l.a[i];
    f[i + m] = l.b[i];
    f[i + m * 2] = r.a[i] + m * 2;
    f[i + m * 3] = r.b[i] + m * 2;
  }
  for (int i = 0; i < m; ++i) {
    if (a[i][lpos] == a[i][rpos] && f[find(i + m * 2)] != f[find(i + m)]) {
      f[find(i + m * 2)] = f[find(i + m)];
      rt.sum--;
    }
  }
  for (int i = 0; i < m * 4; ++i) f[i] = find(f[i]), id[f[i]] = -1;
  for (int i = 0; i < m; ++i) {
    if (id[f[i]] == -1) id[f[i]] = i;
    rt.a[i] = id[f[i]];
  }
  for (int i = m * 3; i < m * 4; ++i) {
    if (id[f[i]] == -1) id[f[i]] = i - m * 2;
    rt.b[i - m * 3] = id[f[i]];
  }
}
void query(int L, int R, int l, int r, int rt, node &ans) {
  if (L <= l && r <= R) {
    ans = T[rt];
    return;
  }
  int mid = l + r >> 1;
  if (R <= mid) {
    query(L, R, l, mid, rt << 1, ans);
    return;
  }
  if (mid < L) {
    query(L, R, mid + 1, r, rt << 1 | 1, ans);
    return;
  }
  node p, q;
  query(L, R, l, mid, rt << 1, p);
  query(L, R, mid + 1, r, rt << 1 | 1, q);
  merge(ans, p, q, mid, mid + 1);
}
void build(int l, int r, int rt) {
  if (l == r) {
    T[rt].sum = 0;
    for (int i = 0; i < m; ++i)
      if (i == 0 || a[i][l] != a[i - 1][l]) {
        T[rt].a[i] = T[rt].b[i] = i;
        T[rt].sum++;
      } else {
        T[rt].a[i] = T[rt].b[i] = T[rt].a[i - 1];
      }
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  merge(T[rt], T[rt << 1], T[rt << 1 | 1], mid, mid + 1);
}
int main() {
  cin.sync_with_stdio(0);
  cin >> m >> n >> q;
  for (int i = 0; i < m; ++i)
    for (int j = 1; j <= n; ++j) cin >> a[i][j];
  build(1, n, 1);
  node ans;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    query(l, r, 1, n, 1, ans);
    cout << ans.sum << endl;
  }
}
