#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e1 + 5;
const int maxM = 1e5 + 5;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
bool mark[4 * maxN];
int n, m, board[maxN][maxM];
int par[4 * maxN], num[4 * maxN];
int getpar(int v) {
  if (par[v] == v) return v;
  return par[v] = getpar(par[v]);
}
bool join(int u, int v) {
  u = getpar(u);
  v = getpar(v);
  if (u == v) return false;
  par[u] = v;
  return true;
}
struct node {
  int cnt, lt, rt;
  int l[maxN], r[maxN];
  node(int tmp = 0) {
    memset(l, 0, sizeof l);
    memset(r, 0, sizeof r);
    cnt = tmp;
    lt = 0;
    rt = 0;
  }
} seg[4 * maxM];
node operator+(node A, node B) {
  if (A.cnt == -1) return B;
  if (B.cnt == -1) return A;
  node C;
  C.lt = A.lt;
  C.rt = B.rt;
  C.cnt = A.cnt + B.cnt;
  int mx =
      max(*max_element(A.l, A.l + maxN), *max_element(A.r, A.r + maxN)) + 1;
  for (int i = 0; i < n; i++) {
    B.l[i] += mx;
    B.r[i] += mx;
  }
  iota(par, par + 4 * maxN, 0);
  int x = A.rt;
  for (int i = 0; i < n; i++) {
    if (board[i][x - 1] == board[i][x]) C.cnt -= join(A.r[i], B.l[i]);
  }
  memset(mark, 0, sizeof mark);
  for (int i = 0; i < n; i++) {
    mark[getpar(A.l[i])] = true;
    mark[getpar(B.r[i])] = true;
  }
  memset(num, -1, sizeof num);
  int cmp = 0;
  for (int i = 0; i < 4 * maxN; i++)
    if (mark[i]) num[i] = cmp++;
  for (int i = 0; i < n; i++) {
    C.l[i] = num[getpar(A.l[i])];
    C.r[i] = num[getpar(B.r[i])];
  }
  return C;
}
void build(int id = 1, int s = 0, int e = m) {
  if (e - s <= 1) {
    seg[id].lt = s;
    seg[id].rt = e;
    int cmp = 0;
    seg[id].l[0] = seg[id].r[0] = 0;
    for (int i = 1; i < n; i++) {
      if (board[i][s] == board[i - 1][s])
        seg[id].l[i] = seg[id].r[i] = cmp;
      else
        seg[id].l[i] = seg[id].r[i] = ++cmp;
    }
    seg[id].cnt = cmp + 1;
    return;
  }
  int md = (s + e) / 2;
  build(2 * id, s, md);
  build(2 * id + 1, md, e);
  seg[id] = seg[2 * id] + seg[2 * id + 1];
  return;
}
node fetch(int l, int r, int id = 1, int s = 0, int e = m) {
  if (l <= s && e <= r) return seg[id];
  if (l >= e || s >= r) return node(-1);
  int md = (s + e) / 2;
  return fetch(l, r, 2 * id, s, md) + fetch(l, r, 2 * id + 1, md, e);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  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", &board[i][j]);
  build();
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    node ans = fetch(l, r);
    printf("%d\n", ans.cnt);
  }
  return 0;
}
