#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
const int M = 2e6 + 7;
int a[11][N], n, m, q, p[M];
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
int L[N][11], R[N][11], sum[N], clk;
void up(int x, int l, int r) {
  int mid = (l + r) >> 1;
  sum[x] = sum[x << 1] + sum[x << 1 | 1];
  for (int i = 1; i <= n; i++) {
    p[L[x << 1][i]] = L[x << 1][i];
    p[L[x << 1 | 1][i]] = L[x << 1 | 1][i];
    p[R[x << 1][i]] = R[x << 1][i];
    p[R[x << 1 | 1][i]] = R[x << 1 | 1][i];
  }
  for (int i = 1; i <= n; i++)
    if (a[i][mid] == a[i][mid + 1]) {
      int p1 = find(R[x << 1][i]), p2 = find(L[x << 1 | 1][i]);
      if (p1 != p2) {
        sum[x]--;
        p[p1] = p2;
      }
    }
  for (int i = 1; i <= n; i++) {
    L[x][i] = find(L[x << 1][i]);
    R[x][i] = find(R[x << 1 | 1][i]);
  }
}
void build(int x, int l, int r) {
  if (l == r) {
    for (int i = 1; i <= n; i++) {
      if (a[i][l] == a[i - 1][l])
        L[x][i] = R[x][i] = L[x][i - 1];
      else
        L[x][i] = R[x][i] = ++clk, sum[x]++;
    }
  } else {
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    up(x, l, r);
  }
}
int n_ans, n_L[11], n_R[11];
void query(int x, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) {
    if (!n_ans) {
      n_ans = sum[x];
      for (int i = 1; i <= n; i++) n_L[i] = L[x][i], n_R[i] = R[x][i];
    } else {
      n_ans += sum[x];
      for (int i = 1; i <= n; i++) {
        p[n_L[i]] = n_L[i];
        p[L[x][i]] = L[x][i];
        p[n_R[i]] = n_R[i];
        p[R[x][i]] = R[x][i];
      }
      for (int i = 1; i <= n; i++)
        if (a[i][l - 1] == a[i][l]) {
          int p1 = find(n_R[i]), p2 = find(L[x][i]);
          if (p1 != p2) {
            n_ans--;
            p[p1] = p2;
          }
        }
      for (int i = 1; i <= n; i++) {
        n_L[i] = find(n_L[i]);
        n_R[i] = find(R[x][i]);
      }
    }
  } else {
    int mid = (l + r) >> 1;
    if (ql <= mid) query(x << 1, l, mid, ql, qr);
    if (qr > mid) query(x << 1 | 1, mid + 1, r, ql, qr);
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  build(1, 1, m);
  for (int i = 1; i <= q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    n_ans = 0;
    query(1, 1, m, l, r);
    printf("%d\n", n_ans);
  }
}
