#include <bits/stdc++.h>
using namespace std;
inline void cmin(int &x, int y) {
  if (y < x) x = y;
}
inline void cmax(int &x, int y) {
  if (y > x) x = y;
}
const int N = 1000006;
int a[12][N], sum[N], tmp[N], bcj[N], f[N][22], id[N], n, m, T, i, j, l, r;
int inline read() {
  char ch = getchar();
  int z = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    z = z * 10 + ch - '0';
    ch = getchar();
  }
  return z * f;
}
int find(int x) {
  if (bcj[x] == x) return x;
  return bcj[x] = find(bcj[x]);
}
int calc(int f[], int g[], int j, int k) {
  int i, ans = 0;
  for ((i) = (1); (i) <= (n + n); ++i) bcj[i] = f[i];
  for ((i) = (1); (i) <= (n + n); ++i) bcj[n + n + i] = n + n + g[i];
  for ((i) = (1); (i) <= (n); ++i)
    if (a[i][j] == a[i][k] && find(n + i) != find(n + n + i)) {
      ++ans;
      bcj[find(n + n + i)] = find(n + i);
    }
  return ans;
}
void build(int l, int r, int x) {
  int mid = l + r >> 1, i;
  if (l == r) {
    int ans = 1;
    for ((i) = (2); (i) <= (n); ++i)
      if (a[i][l] != a[i - 1][l]) ++ans;
    sum[x] = ans;
    for ((i) = (1); (i) <= (n); ++i)
      if (i == 1 || a[i][l] != a[i - 1][l])
        f[x][i] = i;
      else
        f[x][i] = f[x][i - 1];
    for ((i) = (1); (i) <= (n); ++i) f[x][n + i] = f[x][i];
  } else {
    build(l, mid, x * 2);
    build(mid + 1, r, x * 2 + 1);
    sum[x] = sum[x * 2] + sum[x * 2 + 1];
    sum[x] -= calc(f[x * 2], f[x * 2 + 1], mid, mid + 1);
    for ((i) = (1); (i) <= (n * 4); ++i) bcj[i] = find(i), id[i] = 0;
    for ((i) = (1); (i) <= (n); ++i) {
      int z = bcj[i];
      if (!id[z]) id[z] = i;
      f[x][i] = id[z];
    }
    for ((i) = (n + 1); (i) <= (n + n); ++i) {
      int z = bcj[n * 2 + i];
      if (!id[z]) id[z] = i;
      f[x][i] = id[z];
    }
  }
}
int query(int l, int r, int x, int s, int t, int g[]) {
  int i;
  if (s <= l && r <= t) {
    for ((i) = (1); (i) <= (n + n); ++i) g[i] = f[x][i];
    return sum[x];
  }
  int mid = l + r >> 1;
  if (t <= mid) return query(l, mid, x * 2, s, t, g);
  if (s > mid) return query(mid + 1, r, x * 2 + 1, s, t, g);
  int h1[22], h2[22];
  int ans =
      query(l, mid, x * 2, s, t, h1) + query(mid + 1, r, x * 2 + 1, s, t, h2);
  ans -= calc(h1, h2, mid, mid + 1);
  for ((i) = (1); (i) <= (n * 4); ++i) bcj[i] = find(i), id[i] = 0;
  for ((i) = (1); (i) <= (n); ++i) {
    int z = bcj[i];
    if (!id[z]) id[z] = i;
    g[i] = id[z];
  }
  for ((i) = (n + 1); (i) <= (n + n); ++i) {
    int z = bcj[n * 2 + i];
    if (!id[z]) id[z] = i;
    g[i] = id[z];
  }
  return ans;
}
int main() {
  n = read();
  m = read();
  T = read();
  for ((i) = (1); (i) <= (n); ++i)
    for ((j) = (1); (j) <= (m); ++j) a[i][j] = read();
  build(1, m, 1);
  while (T--) {
    l = read();
    r = read();
    printf("%d\n", query(1, m, 1, l, r, tmp));
  }
  return 0;
}
