#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int maxn = 1e5 + 10;
pair<int, int> a[15][maxn];
vector<pair<int, int> > vall[4 * maxn], valr[4 * maxn];
int Sz[4 * maxn];
int n, m, q;
int mrgz;
vector<int> decompos;
map<pair<int, int>, pair<int, int> > par;
pair<int, int> Find(pair<int, int> a) {
  if (!par.count(a)) return a;
  return (par[a] = Find(par[a]));
}
void Merge(pair<int, int> a, pair<int, int> b) {
  pair<int, int> p1 = Find(a), p2 = Find(b);
  if (p1 == p2) return;
  par[p1] = p2;
  mrgz++;
}
void merge(vector<pair<int, int> > &a, vector<pair<int, int> > &b,
           vector<pair<int, int> > &c, vector<pair<int, int> > &d) {
  par.clear();
  for (int i = 0; i < n; i++) {
    if (b[i].first == c[i].first) {
      Merge(b[i], c[i]);
    }
  }
  for (int i = 0; i < n; i++) {
    a[i] = Find(a[i]);
    b[i] = Find(b[i]);
    c[i] = Find(c[i]);
    d[i] = Find(d[i]);
  }
}
void build(int l = 0, int r = m - 1, int ind = 1) {
  if (l == r) {
    set<pair<int, int> > s;
    s.clear();
    for (int i = 0; i < n; i++) {
      s.insert(a[i][l]);
      vall[ind].push_back(a[i][l]);
      valr[ind].push_back(a[i][l]);
    }
    Sz[ind] = (s).size();
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, 2 * ind);
  build(mid + 1, r, 2 * ind + 1);
  vector<pair<int, int> > vrl = vall[2 * ind + 1], vrr = valr[2 * ind + 1],
                          vll = vall[2 * ind], vlr = valr[2 * ind];
  mrgz = 0;
  merge(vll, vlr, vrl, vrr);
  vall[ind] = vll;
  valr[ind] = vrr;
  Sz[ind] = Sz[2 * ind] + Sz[2 * ind + 1] - mrgz;
}
void ask(int targl, int targr, int l = 0, int r = m - 1, int ind = 1) {
  if (l > r) return;
  if (r < targl || targr < l) return;
  if (targl <= l && r <= targr) {
    decompos.push_back(ind);
    return;
  }
  int mid = (l + r) / 2;
  ask(targl, targr, l, mid, 2 * ind);
  ask(targl, targr, mid + 1, r, 2 * ind + 1);
}
int solve(int l, int r) {
  decompos.clear();
  ask(l - 1, r - 1);
  vector<pair<int, int> > vll = vall[decompos[0]], vlr = valr[decompos[0]], vrl,
                          vrr;
  int ans = Sz[decompos[0]];
  for (int i = 1; i <= (decompos).size() - 1; i++) {
    mrgz = 0;
    vrl = vall[decompos[i]];
    vrr = valr[decompos[i]];
    merge(vll, vlr, vrl, vrr);
    vlr = vrr;
    ans = ans + Sz[decompos[i]] - mrgz;
  }
  return ans;
}
int main() {
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) scanf("%d", &a[i][j].first);
  }
  int cmp = 0;
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      a[i][j].second = cmp++;
      while (i < n - 1 && a[i][j].first == a[i + 1][j].first) {
        a[i + 1][j].second = a[i][j].second;
        i++;
      }
    }
  }
  build();
  for (int i = 0; i < q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", solve(l, r));
  }
}
