#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
using namespace std;
long long poww(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
const int maxn = 10 + 5;
const int maxm = 1000 * 100 + 5;
const long long inf = 9223372036854775807;
const long long mod = 1e9 + 7;
const int lg = 20;
int par[lg][maxm], n, m, q, a[maxn][maxm], cn;
map<int, int> root;
struct node {
  int L, R, cnt, la[maxn], ra[maxn];
  node() {
    L = R = cnt = 0;
    for (int i = 0; i < maxn; i++) la[i] = ra[i] = 0;
  }
};
node seg[4 * maxm];
int getpar(int h, int v) {
  return v == par[h][v] ? v : par[h][v] = getpar(h, par[h][v]);
}
int getroot(int v) {
  return (!root.count(v) || root[v] == v) ? v : root[v] = getroot(root[v]);
}
void dm(int u, int v) {
  u = getroot(u);
  v = getroot(v);
  if (u == v) return;
  root[v] = u;
}
node merge(const node &u, const node &v) {
  if (u.cnt == 0) return v;
  if (v.cnt == 0) return u;
  root.clear();
  node res;
  res.L = u.L;
  res.R = v.R;
  res.cnt = u.cnt + v.cnt;
  for (int i = 0; i < n; i++) {
    if (a[i][u.R] == a[i][v.L] && getroot(u.ra[i]) != getroot(v.la[i])) {
      dm(u.ra[i], v.la[i]);
      res.cnt--;
    }
  }
  for (int i = 0; i < n; i++) {
    res.la[i] = getroot(u.la[i]);
    res.ra[i] = getroot(v.ra[i]);
  }
  return res;
}
void build(int h = 0, int x = 1, int lx = 0, int rx = m) {
  if (rx - lx == 1) {
    seg[x].L = seg[x].R = lx;
    cn = 1;
    seg[x].la[0] = seg[x].ra[0] = lx + 1;
    for (int i = 1; i < n; i++) {
      if (a[i][lx] == a[i - 1][lx]) {
        seg[x].la[i] = seg[x].ra[i] = seg[x].la[i - 1];
      } else {
        cn++;
        seg[x].la[i] = seg[x].ra[i] = i * m + lx + 1;
      }
    }
    seg[x].cnt = cn;
    return;
  }
  int mid = lx + rx >> 1;
  build(h + 1, x << 1, lx, mid);
  build(h + 1, x << 1 | 1, mid, rx);
  seg[x] = merge(seg[x << 1], seg[x << 1 | 1]);
}
node get(int l, int r, int h = 0, int x = 1, int lx = 0, int rx = m) {
  if (lx >= r || rx <= l) return node();
  if (lx >= l && rx <= r) {
    return seg[x];
  }
  int mid = lx + rx >> 1;
  return merge(get(l, r, h + 1, x << 1, lx, mid),
               get(l, r, h + 1, x << 1 | 1, mid, rx));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  build();
  int l, r;
  while (q--) {
    cin >> l >> r;
    l--;
    cout << get(l, r).cnt << endl;
  }
}
