#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, b[10][N], par[40], vis[40];
struct node {
  int t[2][10], sz;
  node() : sz(0){};
} t[4 * N];
void uno(node &x, int l) {
  x.sz = 0;
  for (int i = 0; i < n; i++) {
    x.t[0][i] = x.t[1][i] = x.sz;
    if (i == n - 1 || b[i][l] != b[i + 1][l]) x.sz++;
  }
}
void compress(node &x) {
  for (int i = 0; i < 4 * n; i++) par[i] = 0;
  int cnt = 0;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < n; j++) par[x.t[i][j]] = 1;
  for (int i = 1; i < 4 * n; i++) par[i] += par[i - 1];
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < n; j++) x.t[i][j] = par[x.t[i][j]] - 1;
}
int parent(int u) { return par[u] == u ? u : par[u] = parent(par[u]); }
void combine(node &x, node y, node z, int mid) {
  if (y.sz == 0)
    x = z;
  else if (z.sz == 0)
    x = y;
  else {
    x.sz = y.sz + z.sz;
    for (int i = 0; i < 4 * n; i++) par[i] = i;
    for (int i = 0; i < n; i++) {
      z.t[0][i] += 2 * n;
      z.t[1][i] += 2 * n;
      x.t[0][i] = y.t[0][i];
      x.t[1][i] = z.t[1][i];
      if (b[i][mid] == b[i][mid + 1])
        if (parent(z.t[0][i]) != parent(y.t[1][i])) {
          par[parent(z.t[0][i])] = parent(y.t[1][i]);
          x.sz--;
        }
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 2; j++) x.t[j][i] = parent(x.t[j][i]);
    compress(x);
  }
}
void print(node &x) {
  cout << "S: " << x.sz << endl;
  for (int i = 0; i < n; i++) cout << x.t[0][i] << " " << x.t[1][i] << endl;
}
void init(int k, int l, int r) {
  if (l == r) {
    uno(t[k], l);
  } else {
    int mid = (l + r) >> 1;
    init(k << 1, l, mid);
    init(k << 1 | 1, mid + 1, r);
    combine(t[k], t[k << 1], t[k << 1 | 1], mid);
  }
}
node _query(int k, int l, int r, int x, int y) {
  node ret;
  if (l > y || r < x) {
    return ret;
  } else if (l >= x && r <= y) {
    ret = t[k];
  } else {
    int mid = (l + r) >> 1;
    node left = _query(k << 1, l, mid, x, y),
         right = _query(k << 1 | 1, mid + 1, r, x, y);
    combine(ret, left, right, mid);
  }
  return ret;
}
int main() {
  int q;
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%d", &b[i][j]);
    }
  init(1, 0, m - 1);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--;
    r--;
    printf("%d\n", _query(1, 0, m - 1, l, r).sz);
  }
  return 0;
}
