#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n, m, q, nn, l1, r1, Tar;
int tree[5 * N];
int par[5 * N][2][12];
int D[12][N];
void build(int cur, int l, int r) {
  if (l == r) {
    for (int i = 0; i < n; i++) par[cur][0][i] = par[cur][1][i] = l * n + i;
    int cnt = n;
    for (int i = 0; i < n - 1; i++) {
      if (D[i][l] == D[i + 1][l])
        par[cur][0][i + 1] = par[cur][1][i + 1] = par[cur][0][i], cnt--;
    }
    tree[cur] = cnt;
    return;
  }
  int M = l + r >> 1;
  build(2 * cur + 1, l, M);
  build(2 * cur + 2, M + 1, r);
  int cnt = tree[2 * cur + 1] + tree[2 * cur + 2], pp[10];
  for (int i = 0; i < n; i++)
    par[cur][0][i] = par[2 * cur + 1][0][i],
    par[cur][1][i] = par[2 * cur + 2][1][i], pp[i] = par[2 * cur + 1][1][i];
  for (int i = 0; i < n; i++) {
    if (D[i][M] == D[i][M + 1]) {
      if (pp[i] != par[2 * cur + 2][0][i]) {
        cnt--;
        int W = pp[i], W1 = par[2 * cur + 2][0][i];
        for (int j = 0; j < n; j++) {
          if (par[cur][0][j] == W) par[cur][0][j] = W1;
          if (par[cur][1][j] == W) par[cur][1][j] = W1;
          if (pp[j] == W) pp[j] = W1;
        }
      }
    }
  }
  tree[cur] = cnt;
}
int qry[5 * N][2][10];
int query(int cur, int l, int r, int x, int y) {
  if (r < x || y < l) return 0;
  if (x <= l && r <= y) {
    for (int i = 0; i < n; i++)
      qry[cur][0][i] = par[cur][0][i], qry[cur][1][i] = par[cur][1][i];
    return tree[cur];
  }
  int M = l + r >> 1, cnt = 0, c1, c2, pp[10];
  c1 = query(2 * cur + 1, l, M, x, y);
  c2 = query(2 * cur + 2, M + 1, r, x, y);
  for (int i = 0; i < n; i++) {
    if (c1)
      qry[cur][0][i] = qry[2 * cur + 1][0][i], pp[i] = qry[2 * cur + 1][1][i];
    else
      qry[cur][0][i] = qry[2 * cur + 2][0][i];
    if (c2)
      qry[cur][1][i] = qry[2 * cur + 2][1][i];
    else
      qry[cur][1][i] = qry[2 * cur + 1][1][i];
  }
  cnt = c1 + c2;
  if (c1 && c2)
    for (int i = 0; i < n; i++) {
      if (D[i][M] == D[i][M + 1]) {
        if (pp[i] != qry[2 * cur + 2][0][i]) {
          cnt--;
          int W = pp[i], W1 = qry[2 * cur + 2][0][i];
          for (int j = 0; j < n; j++) {
            if (qry[cur][0][j] == W) qry[cur][0][j] = W1;
            if (qry[cur][1][j] == W) qry[cur][1][j] = W1;
            if (pp[j] == W) pp[j] = W1;
          }
        }
      }
    }
  return cnt;
}
int main() {
  int LL, RR;
  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 >> D[i][j];
  }
  build(0, 0, m - 1);
  for (int i = 0; i < q; i++) {
    cin >> LL >> RR;
    cout << query(0, 0, m - 1, LL - 1, RR - 1) << '\n';
  }
}
