#include <bits/stdc++.h>
using namespace std;
const int mt = 100000 + 5;
struct node {
  int x[11], y[11];
  int sum;
} t[mt << 2];
int mapp[11][mt];
int n, m, q;
int f[mt * 10];
inline int read() {
  int num = 0, flag = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') flag = -1;
  } while (ch < '0' || ch > '9');
  do {
    num = num * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return num * flag;
}
int findf(int x) {
  if (f[x] == x) return x;
  return f[x] = findf(f[x]);
}
node pushup(node a, node b, int mid) {
  node xlk;
  xlk.sum = a.sum + b.sum;
  for (int i = 1; i <= n; i++) {
    f[a.x[i]] = a.x[i];
    f[a.y[i]] = a.y[i];
    f[b.x[i]] = b.x[i];
    f[b.y[i]] = b.y[i];
  }
  for (int i = 1; i <= n; i++) {
    if (mapp[i][mid] == mapp[i][mid + 1]) {
      if (findf(a.y[i]) != findf(b.x[i])) {
        int aaaa = findf(a.y[i]);
        int bbbb = findf(b.x[i]);
        if (aaaa != bbbb) f[aaaa] = bbbb;
        xlk.sum--;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    xlk.x[i] = findf(a.x[i]);
    xlk.y[i] = findf(b.y[i]);
  }
  return xlk;
}
int tot = 0;
void build(int rt, int l, int r) {
  if (l == r) {
    for (int i = 1; i <= n; i++) {
      if (mapp[i - 1][l] != mapp[i][l])
        t[rt].x[i] = ++tot, t[rt].y[i] = tot, t[rt].sum++;
      else
        t[rt].x[i] = t[rt].y[i] = t[rt].x[i - 1];
    }
    return;
  }
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  t[rt] = pushup(t[rt << 1], t[rt << 1 | 1], mid);
}
node query(int rt, int l, int r, int lft, int rgt) {
  node ans;
  if (lft <= l && r <= rgt) {
    ans = t[rt];
    return ans;
  }
  int mid = (l + r) >> 1;
  if (rgt <= mid)
    return query(rt << 1, l, mid, lft, rgt);
  else if (mid < lft)
    return query(rt << 1 | 1, mid + 1, r, lft, rgt);
  return pushup(query(rt << 1, l, mid, lft, rgt),
                query(rt << 1 | 1, mid + 1, r, lft, rgt), mid);
}
int main() {
  n = read(), m = read(), q = read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) mapp[i][j] = read();
  build(1, 1, m);
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    node ans = query(1, 1, m, l, r);
    printf("%d\n", ans.sum);
  }
  return 0;
}
