#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[10][maxn];
int n, m;
struct node {
  int cnt = 0;
  pair<int, int> ft[10], bk[10];
  void Set(int x, int y) {
    for (int i = 0; i < n; i++) {
      if (ft[i].second == x) ft[i].second = y;
      if (bk[i].second == x) bk[i].second = y;
    }
    cnt--;
  }
} t[maxn * 4];
node Merge(node a, node b) {
  node ret;
  pair<int, int> vis[10];
  int num = 0;
  ret.cnt = a.cnt + b.cnt;
  for (int i = 0; i < n; i++) {
    ret.ft[i] = a.ft[i];
    ret.bk[i] = b.bk[i];
  }
  for (int i = 0; i < n; i++)
    if (a.bk[i].first == b.ft[i].first && a.bk[i].second != b.ft[i].second) {
      pair<int, int> p = make_pair(a.bk[i].second, b.ft[i].second);
      bool found = 0;
      for (int j = 0; j < num; j++)
        if (vis[j] == p) {
          found = 1;
          break;
        }
      if (!found) {
        vis[num++] = p;
        a.Set(p.first, p.second);
        ret.Set(p.first, p.second);
      }
    }
  return ret;
}
void build(int id, int L, int R) {
  if (L == R) {
    t[id].cnt = n;
    for (int i = 0; i < n; i++) {
      t[id].ft[i].first = t[id].bk[i].first = a[i][L];
      if (i && a[i][L] == a[i - 1][L]) {
        t[id].ft[i].second = t[id].bk[i].second = t[id].ft[i - 1].second;
        t[id].cnt--;
      } else
        t[id].ft[i].second = t[id].bk[i].second = L * 10 + i;
    }
  } else {
    int mid = L + R >> 1;
    build(id << 1, L, mid);
    build(id << 1 | 1, mid + 1, R);
    t[id] = Merge(t[id << 1], t[id << 1 | 1]);
  }
}
node query(int id, int L, int R, int l, int r) {
  if (l <= L && R <= r)
    return t[id];
  else {
    int mid = L + R >> 1;
    if (r <= mid)
      return query(id << 1, L, mid, l, r);
    else if (l > mid)
      return query(id << 1 | 1, mid + 1, R, l, r);
    else
      return Merge(query(id << 1, L, mid, l, r),
                   query(id << 1 | 1, mid + 1, R, l, r));
  }
}
int main() {
  int q;
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  build(1, 1, m);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", query(1, 1, m, l, r).cnt);
  }
}
