#include <bits/stdc++.h>
using namespace std;
int n, m, q;
struct node {
  int ls[13];
  int rs[13];
  int l, r;
  int num;
} qu[500500], ans, kong;
struct nod {
  int l, r;
} tree[500050];
int a[13][100200], tot, fa[10000050];
bool boo;
int getfa(int i) {
  if (fa[i] == i) return fa[i];
  fa[i] = getfa(fa[i]);
  return fa[i];
}
node operator+(node aa, node bb) {
  node c = kong;
  c.num = aa.num + bb.num;
  for (int i = 1; i <= n; i++)
    if ((a[i][aa.r] == a[i][bb.l]) && (getfa(aa.rs[i]) != getfa(bb.ls[i]))) {
      c.num--;
      fa[fa[aa.rs[i]]] = fa[bb.ls[i]];
    }
  for (int i = 1; i <= n; i++) {
    c.ls[i] = getfa(aa.ls[i]);
    c.rs[i] = getfa(bb.rs[i]);
  }
  c.l = aa.l;
  c.r = bb.r;
  return c;
}
void dfs(int j, int l, int r) {
  tree[j].l = l;
  tree[j].r = r;
  if (l == r) {
    qu[j].l = l;
    qu[j].r = l;
    for (int i = 1; i <= n; i++) {
      qu[j].ls[i] = ++tot;
      qu[j].rs[i] = tot;
    }
    for (int i = 1; i < n; i++)
      if (a[i][l] == a[i + 1][l]) {
        getfa(qu[j].ls[i]);
        getfa(qu[j].ls[i + 1]);
        fa[fa[qu[j].ls[i]]] = fa[qu[j].ls[i + 1]];
      } else
        qu[j].num++;
    qu[j].num++;
    for (int i = 1; i <= n; i++) {
      qu[j].ls[i] = getfa(qu[j].ls[i]);
      qu[j].rs[i] = getfa(qu[j].ls[i]);
    }
  } else {
    int m = (l + r) >> 1;
    dfs(j << 1, l, m);
    dfs(j * 2 + 1, (m + 1), r);
    qu[j] = qu[j << 1] + qu[j * 2 + 1];
  }
}
void que(int i, int l, int r) {
  if ((tree[i].l > r) || (tree[i].r < l)) return;
  if ((tree[i].l >= l) && (tree[i].r <= r)) {
    for (int j = 1; j <= n; j++) {
      fa[qu[i].ls[j]] = qu[i].ls[j];
      fa[qu[i].rs[j]] = qu[i].rs[j];
    }
    if (!boo) {
      ans = qu[i];
      boo = 1;
    } else
      ans = ans + qu[i];
  } else {
    que(i << 1, l, r);
    que(i * 2 + 1, l, r);
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= 2e6; i++) fa[i] = i;
  dfs(1, 1, m);
  for (int i = 1; i <= q; i++) {
    boo = 0;
    int l, r;
    scanf("%d%d", &l, &r);
    que(1, l, r);
    printf("%d\n", ans.num);
  }
  return 0;
}
