#include <bits/stdc++.h>
using namespace std;
const int N = 10, M = 100000;
int n, m, q;
int a[M][N];
struct Node {
  int cnt;
  int8_t lt[N], rt[N];
} w[M << 2];
void print(int l, int r, const Node& p) {
  printf("[%d,%d] => lt=", l, r);
  for (int i = 0; i < n; ++i) printf("%d,", p.lt[i]);
  printf("  rt=");
  for (int i = 0; i < n; ++i) printf("%d,", p.rt[i]);
  printf("\n");
}
int ds[4 * N];
int find_ds(int i) { return ds[i] == i ? i : (ds[i] = find_ds(ds[i])); }
int mp[4 * N];
vector<int> ns;
void merge(Node& p, int pos, const Node& ls, const Node& rs1) {
  static Node rs;
  rs = rs1;
  int ma = max(*max_element(ls.rt, ls.rt + n), *max_element(ls.lt, ls.lt + n));
  fill(mp, mp + 4 * N, -1);
  for (int i = 0; i < n; ++i) {
    if (mp[rs.lt[i]] == -1) mp[rs.lt[i]] = ++ma;
    if (mp[rs.rt[i]] == -1) mp[rs.rt[i]] = ++ma;
  }
  for (int i = 0; i < n; ++i) {
    rs.lt[i] = mp[rs.lt[i]];
    rs.rt[i] = mp[rs.rt[i]];
  }
  for (int i = 0; i <= ma; ++i) ds[i] = i;
  p.cnt = ls.cnt + rs.cnt;
  for (int i = 0; i < n; ++i) {
    if (a[pos][i] != a[pos + 1][i]) continue;
    int x = find_ds(ls.rt[i]), y = find_ds(rs.lt[i]);
    if (x == y) continue;
    ds[x] = y;
    --p.cnt;
  }
  ns.clear();
  for (int i = 0; i < n; ++i) {
    ns.push_back(p.lt[i] = find_ds(ls.lt[i]));
    ns.push_back(p.rt[i] = find_ds(rs.rt[i]));
  }
  sort(ns.begin(), ns.end());
  ns.erase(unique(ns.begin(), ns.end()), ns.end());
  ma = 0;
  for (int i : ns) mp[i] = ma++;
  for (int i = 0; i < n; ++i) {
    p.lt[i] = mp[p.lt[i]];
    p.rt[i] = mp[p.rt[i]];
  }
}
void init(int o, int l, int r) {
  if (l == r) {
    Node& p = w[o];
    p.lt[0] = p.rt[0] = 0;
    for (int i = 1; i < n; ++i) {
      p.lt[i] = p.rt[i] =
          a[l][i] == a[l][i - 1] ? p.lt[i - 1] : p.lt[i - 1] + 1;
    }
    p.cnt = p.lt[n - 1] + 1;
  } else {
    int m = (l + r) >> 1;
    init(o << 1, l, m);
    init(o << 1 | 1, m + 1, r);
    merge(w[o], m, w[o << 1], w[o << 1 | 1]);
  }
}
int L, R;
Node query(int o, int l, int r) {
  if (L <= l && r <= R) {
    return w[o];
  }
  int mid = (l + r) >> 1;
  Node p;
  if (L <= mid && mid < R) {
    Node x = query(o << 1, l, mid);
    Node y = query(o << 1 | 1, mid + 1, r);
    merge(p, mid, x, y);
  } else if (L <= mid) {
    p = query(o << 1, l, mid);
  } else if (mid < R) {
    p = query(o << 1 | 1, mid + 1, r);
  }
  return p;
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[j][i]);
    }
  }
  init(1, 0, m - 1);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d", &L, &R);
    --L, --R;
    Node p = query(1, 0, m - 1);
    printf("%d\n", p.cnt);
  }
  return 0;
}
