#include <bits/stdc++.h>
using namespace std;
int n, m, q, i, j, x, y, k, res, ns;
int a[12][100100], fa[1001000], s[100], t[100];
int w[400100][22], it[400100], l[400100], h[400100];
int ms(int x, int y) { return x + (y - 1) * n; }
int findset(int x) {
  if (fa[x] < 0) return x;
  fa[x] = findset(fa[x]);
  return fa[x];
}
int match(int x, int y) {
  if (x == y) return 0;
  if (fa[x] > fa[y]) {
    fa[y] += fa[x];
    fa[x] = y;
  } else {
    fa[x] += fa[y];
    fa[y] = x;
  }
  return 1;
}
void build(int t, int x, int y) {
  l[t] = x;
  h[t] = y;
  if (x == y) {
    for (i = 1; i < n; i++)
      if (a[i][x] == a[i + 1][x])
        it[t] += match(findset(ms(i, x)), findset(ms(i + 1, x)));
    for (i = 1; i <= n; i++) {
      w[t][i] = findset(ms(i, x));
      w[t][i + n] = findset(ms(i, x));
    }
    return;
  }
  int m = (x + y) / 2;
  build(t * 2, x, m);
  build(t * 2 + 1, m + 1, y);
  it[t] = it[t * 2] + it[t * 2 + 1];
  for (i = 1; i <= n; i++)
    if (a[i][m] == a[i][m + 1])
      it[t] += match(findset(ms(i, m)), findset(ms(i, m + 1)));
  for (i = 1; i <= n; i++) {
    w[t][i] = findset(ms(i, x));
    w[t][i + n] = findset(ms(i, y));
  }
}
void query(int t, int x, int y) {
  if (x > h[t] || y < l[t]) return;
  if (x <= l[t] && h[t] <= y) {
    s[++ns] = t;
    return;
  }
  query(t * 2, x, y);
  query(t * 2 + 1, x, y);
}
bool cmp(int x, int y) { return w[k][x] < w[k][y]; }
int main() {
  scanf("%d %d %d", &n, &m, &q);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  memset(fa, -1, sizeof(fa));
  build(1, 1, m);
  memset(fa, -1, sizeof(fa));
  while (q--) {
    scanf("%d %d", &x, &y);
    ns = 0;
    res = (y - x + 1) * n;
    query(1, x, y);
    for (i = 1; i <= ns; i++) {
      k = s[i];
      res -= it[k];
      for (j = 1; j <= n * 2; j++) t[j] = j;
      sort(t + 1, t + 1 + n * 2, cmp);
      for (j = 1; j < 2 * n; j++)
        if (w[k][t[j]] == w[k][t[j + 1]])
          match(findset((i - 1) * 2 * n + t[j]),
                findset((i - 1) * 2 * n + t[j + 1]));
    }
    for (i = 1; i < ns; i++) {
      k = h[s[i]];
      for (j = 1; j <= n; j++)
        if (a[j][k] == a[j][k + 1])
          res -= match(findset(ms(j, i * 2)), findset(ms(j, i * 2 + 1)));
    }
    printf("%d\n", res);
    for (i = 1; i <= ns * 2 * n; i++) fa[i] = -1;
  }
}
