#include <bits/stdc++.h>
using namespace std;
int N, M, T;
int ini[100001][11];
struct node {
  int pre[24];
  int cnt;
} s[400001];
inline int find(int x, int* fa) {
  for (; x != fa[x]; x = fa[x])
    ;
  return x;
}
inline void upload(node& L, node& R, node& res, int pos) {
  res.cnt = L.cnt + R.cnt;
  int id[50] = {0}, fa[50], jd = 0;
  for (int i = 1; i <= 44; i++) fa[i] = i;
  for (int i = 1; i <= N; i++) {
    if (ini[pos][i] == ini[pos + 1][i]) {
      int x = find(L.pre[11 + i], fa), y = find(R.pre[i] + 22, fa);
      if (x == y) continue;
      --res.cnt;
      fa[x] = y;
    }
  }
  for (int i = 1; i <= N; i++) {
    int& x = id[find(L.pre[i], fa)];
    if (!x) x = ++jd;
    res.pre[i] = x;
    int& y = id[find(R.pre[i + 11] + 22, fa)];
    if (!y) y = ++jd;
    res.pre[i + 11] = y;
  }
}
void build(int L, int R, int rt) {
  if (L == R) {
    int cnt = 0;
    for (int i = 1; i <= N; i++) {
      if (ini[L][i] != ini[L][i - 1])
        s[rt].pre[i] = s[rt].pre[i + 11] = i, cnt++;
      else
        s[rt].pre[i] = s[rt].pre[i + 11] = s[rt].pre[i - 1];
    }
    s[rt].cnt = cnt;
  } else {
    int mid = L + R >> 1;
    build(L, mid, rt << 1);
    build(mid + 1, R, rt << 1 | 1);
    upload(s[rt << 1], s[rt << 1 | 1], s[rt], mid);
  }
}
node query(int L, int R, int _l, int _r, int rt) {
st:
  if (L >= _l && R <= _r) return s[rt];
  int mid = L + R >> 1;
  if (_l > mid) {
    L = mid + 1;
    rt = rt << 1 | 1;
    goto st;
  }
  if (_r <= mid) {
    R = mid;
    rt <<= 1;
    goto st;
  }
  node a = query(L, mid, _l, _r, rt << 1),
       b = query(mid + 1, R, _l, _r, rt << 1 | 1), res;
  upload(a, b, res, mid);
  return res;
}
int main() {
  scanf("%d%d%d", &N, &M, &T);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) {
      scanf("%d", &ini[j][i]);
    }
  build(1, M, 1);
  for (int i = 1; i <= T; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", query(1, M, a, b, 1).cnt);
  }
  return 0;
}
