#include <bits/stdc++.h>
using namespace std;
const int maxm = 1e5 + 233;
const int CDD = 360;
int n, m, q, g[11][maxm], p[maxm << 2], id[maxm << 2];
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
struct Node {
  int val, L[11], R[11], siz;
} * ch[maxm << 2], *emp;
inline int unite(int x, int y) {
  int a = find(x), b = find(y);
  if (a == b) return 0;
  p[a] = b;
  return 1;
}
Node *perx, *pery;
inline Node* merge(Node* x, Node* y, int pos) {
  if (x->val == -1) return y;
  if (y->val == -1) return x;
  Node* z = new Node;
  perx->val = x->val;
  perx->siz = x->siz;
  for (int i = 1; i <= n; i++) perx->L[i] = x->L[i], perx->R[i] = x->R[i];
  pery->val = y->val;
  pery->siz = y->siz;
  for (int i = 1; i <= n; i++) pery->L[i] = y->L[i], pery->R[i] = y->R[i];
  z->val = x->val + y->val;
  for (int i = 1; i <= n; i++) y->L[i] += x->siz, y->R[i] += x->siz;
  for (int i = 1; i <= n; i++) {
    int buf = y->L[i];
    p[buf] = buf;
    buf = y->R[i];
    p[buf] = buf;
    buf = x->L[i];
    p[buf] = buf;
    buf = x->R[i];
    p[buf] = buf;
  }
  for (int i = 1; i <= n; i++)
    if (g[i][pos] == g[i][pos + 1]) {
      z->val -= unite(x->R[i], y->L[i]);
    }
  for (int i = 1; i <= n; i++) {
    z->L[i] = find(x->L[i]);
    z->R[i] = find(y->R[i]);
    id[z->L[i]] = -1;
    id[z->R[i]] = -1;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (id[z->L[i]] == -1) id[z->L[i]] = ++cnt;
    if (id[z->R[i]] == -1) id[z->R[i]] = ++cnt;
    z->L[i] = id[z->L[i]];
    z->R[i] = id[z->R[i]];
  }
  z->siz = cnt;
  x->val = perx->val;
  x->siz = perx->siz;
  for (int i = 1; i <= n; i++) x->L[i] = perx->L[i], x->R[i] = perx->R[i];
  y->val = pery->val;
  y->siz = pery->siz;
  for (int i = 1; i <= n; i++) y->L[i] = pery->L[i], y->R[i] = pery->R[i];
  return z;
}
void build(int l, int r, int cur) {
  if (l == r) {
    ch[cur] = new Node;
    int& x = ch[cur]->val;
    x = 0;
    for (int i = 1; i <= n; i++) {
      if (i == 1 || g[i][l] != g[i - 1][l]) x++;
      ch[cur]->L[i] = ch[cur]->R[i] = x;
    }
    ch[cur]->siz = x;
    return;
  }
  int mid = (l + r) >> 1, lc = cur << 1, rc = lc | 1;
  build(l, mid, lc);
  build(mid + 1, r, rc);
  ch[cur] = merge(ch[lc], ch[rc], mid);
  return;
}
Node* query(int l, int r, int cur, int x, int y) {
  if (r < x || l > y) return emp;
  if (x <= l && r <= y) {
    return ch[cur];
  }
  int mid = (l + r) >> 1, lc = cur << 1, rc = lc | 1;
  return merge(query(l, mid, lc, x, y), query(mid + 1, r, rc, x, y), mid);
}
int main() {
  perx = new Node;
  pery = new Node;
  emp = new Node;
  emp->val = -1;
  cin >> n >> m >> q;
  int siz = (m + CDD - 1) / CDD;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &g[i][j]);
  build(1, m, 1);
  for (int i = 1; i <= q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", query(1, m, 1, l, r)->val);
  }
  return 0;
}
