#include <bits/stdc++.h>
using namespace std;
int const K = 10;
struct node {
  int a;
  int L[K], R[K], PL[K], PR[K];
};
const signed long long int INF = 10e8;
const int N = 100000;
int n, m, q;
int a[11][N];
node t[N * 5];
node G;
node un(node t1, node t2) {
  node res;
  for (int i(0); i < n; i++) {
    res.L[i] = t1.L[i];
    res.R[i] = t2.R[i];
    res.PL[i] = t1.PL[i];
    res.PR[i] = t2.PR[i];
  }
  res.a = t1.a + t2.a;
  for (int i(0); i < n; i++) {
    if (t1.R[i] == t2.L[i] && t1.PR[i] != t2.PL[i]) {
      res.a--;
      int cur = t2.PL[i];
      for (int j(0); j < n; j++) {
        if (res.PR[j] == cur) {
          res.PR[j] = t1.PR[i];
        }
        if (res.PL[j] == cur) {
          res.PL[j] = t1.PR[i];
        }
        if (t1.PR[j] == cur) {
          t1.PR[j] = t1.PR[i];
        }
        if (t2.PL[j] == cur) {
          t2.PL[j] = t1.PR[i];
        }
      }
    }
  }
  return res;
}
void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[v].a = n;
    for (int i(0); i < n; i++) {
      t[v].L[i] = a[i][tl];
      t[v].R[i] = a[i][tl];
      int p = (i + 1) * m + tl + 1;
      if (i && t[v].L[i - 1] == t[v].L[i]) {
        p = t[v].PL[i - 1];
        t[v].a--;
      }
      t[v].PL[i] = t[v].PR[i] = p;
    }
    return;
  } else {
    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm);
    build(v * 2 + 1, tm + 1, tr);
    t[v] = un(t[v * 2], t[v * 2 + 1]);
  }
}
void get(int v, int tl, int tr, int l, int r) {
  if (l > r) {
    return;
  }
  if (tl == l && tr == r) {
    if (G.a == 0)
      G = t[v];
    else
      G = un(G, t[v]);
    return;
  } else {
    int tm = (tl + tr) / 2;
    get(v * 2, tl, tm, l, min(r, tm));
    get(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r);
  }
}
bool solve() {
  cin >> n >> m >> q;
  for (int i(0); i < n; i++) {
    for (int j(0); j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  build(1, 0, m - 1);
  for (int i(0); i < q; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    G.a = 0;
    get(1, 0, m - 1, l - 1, r - 1);
    printf("%d\n", G.a);
  }
  return 1;
}
int main() {
  solve();
  return 0;
}
