#include <bits/stdc++.h>
using namespace std;
const int NN = 100001;
int a[11][NN], b[11][NN], t[4 * NN + 1];
pair<int, int> p[NN];
pair<int, int> fl[11][4 * NN + 1], fr[11][4 * NN + 1];
int n, m, i, k, j, f, s, c, x, y, z, q, w, e, l, r, o, fa, fb;
int MM[NN * 10];
int root(int x) {
  if (MM[x] != x) MM[x] = root(MM[x]);
  return MM[x];
}
void modify(int v, int tl, int tr, int pos) {
  if (tl == tr) {
    int i;
    t[v] = b[m][pos] - b[1][pos] + 1;
    for (i = 1; i <= m; i++) {
      fl[i][v] = make_pair(a[i][pos], b[i][pos]);
      fr[i][v] = make_pair(a[i][pos], b[i][pos]);
    }
  } else {
    int c = (tl + tr) >> 1;
    int d = 0;
    int i;
    if (pos <= c)
      modify(v * 2, tl, c, pos);
    else
      modify(v * 2 + 1, c + 1, tr, pos);
    for (i = 1; i <= m; i++) {
      MM[fl[i][v].second] = fl[i][v].second;
      MM[fr[i][v].second] = fr[i][v].second;
      MM[fr[i][v * 2].second] = fr[i][v * 2].second;
      MM[fl[i][v * 2 + 1].second] = fl[i][v * 2 + 1].second;
    }
    for (i = 1; i <= m; i++) {
      fa = root(fr[i][v * 2].second);
      fb = root(fl[i][v * 2 + 1].second);
      if (fr[i][v * 2].first == fl[i][v * 2 + 1].first && fa != fb) {
        d++;
        MM[fa] = fb;
      }
      fl[i][v] = fl[i][v * 2];
      fr[i][v] = fr[i][v * 2 + 1];
    }
    for (i = 1; i <= m; i++) {
      fl[i][v].second = root(fl[i][v].second);
      fr[i][v].second = root(fr[i][v].second);
    }
    t[v] = t[v * 2] + t[v * 2 + 1] - d;
  }
}
void get(int v, int tl, int tr, int l, int r) {
  if (l > r) return;
  if (tl == l && tr == r) {
    int i;
    int d = 0;
    for (i = 1; i <= m; i++) {
      if (!w) p[i] = make_pair(0, 0);
      MM[p[i].second] = p[i].second;
      MM[fl[i][v].second] = fl[i][v].second;
      MM[fr[i][v].second] = fr[i][v].second;
    }
    for (i = 1; i <= m; i++) {
      fa = root(p[i].second);
      fb = root(fl[i][v].second);
      if (p[i].first == fl[i][v].first && fa != fb) {
        d++;
        MM[fa] = fb;
      }
      p[i] = fr[i][v];
    }
    for (i = 1; i <= m; i++) p[i].second = root(p[i].second);
    w += (t[v] - d);
    return;
  }
  int c = (tl + tr) >> 1;
  get(v * 2, tl, c, l, min(c, r));
  get(v * 2 + 1, c + 1, tr, max(l, c + 1), r);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> m >> n >> q;
  for (i = 1; i <= m; i++)
    for (j = 1; j <= n; j++) cin >> a[i][j];
  for (j = 1; j <= n; j++)
    for (i = 1; i <= m; i++) {
      if (a[i][j] != a[i - 1][j]) w++;
      b[i][j] = w;
    }
  for (i = 1; i <= n; i++) modify(1, 1, n, i);
  for (i = 1; i <= q; i++) {
    cin >> x >> y;
    w = 0;
    get(1, 1, n, x, y);
    cout << w << "\n";
  }
  return 0;
}
