#include <bits/stdc++.h>
using namespace std;
template <class BidirIt>
BidirIt prev(BidirIt it,
             typename iterator_traits<BidirIt>::difference_type n = 1) {
  advance(it, -n);
  return it;
}
template <class ForwardIt>
ForwardIt next(ForwardIt it,
               typename iterator_traits<ForwardIt>::difference_type n = 1) {
  advance(it, n);
  return it;
}
const double EPS = 1e-9;
const double PI = 3.141592653589793238462;
template <typename T>
inline T sq(T a) {
  return a * a;
}
const int MAX_M = 1e5 + 5;
int mat[MAX_M][15], n, m;
struct node {
  int left[15], right[15], ans = 0;
  int mat_le[15], mat_ri[15];
} st[MAX_M << 1];
int p[MAX_M * 15];
int fin(int x) { return (p[x] == -1 ? x : p[x] = fin(p[x])); }
int join(int x, int y) {
  x = fin(x), y = fin(y);
  if (x != y) {
    p[x] = y;
    return 1;
  }
  return 0;
}
node combine(const node &lhs, const node &rhs) {
  if (lhs.ans == -1) return rhs;
  if (rhs.ans == -1) return lhs;
  for (int i = 0; i < n; i++) {
    p[lhs.left[i]] = p[lhs.right[i]] = -1;
    p[rhs.left[i]] = p[rhs.right[i]] = -1;
  }
  node ret;
  ret.ans = lhs.ans + rhs.ans;
  for (int i = 0; i < n; i++) {
    if (lhs.mat_ri[i] == rhs.mat_le[i])
      ret.ans -= join(lhs.right[i], rhs.left[i]);
  }
  for (int i = 0; i < n; i++) {
    ret.left[i] = fin(lhs.left[i]);
    ret.right[i] = fin(rhs.right[i]);
    ret.mat_le[i] = lhs.mat_le[i];
    ret.mat_ri[i] = rhs.mat_ri[i];
  }
  return ret;
}
node query(int l, int r) {
  node from_left, from_right;
  from_left.ans = from_right.ans = -1;
  for (l += m, r += m; l <= r; l >>= 1, r >>= 1) {
    if (l & 1) from_left = combine(from_left, st[l++]);
    if (!(r & 1)) from_right = combine(st[r--], from_right);
  }
  return combine(from_left, from_right);
}
int main() {
  int q;
  scanf("%d %d %d", &n, &m, &q);
  for (int j = 0; j < n; j++)
    for (int i = 0; i < m; i++) scanf("%d", &mat[i][j]);
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      st[m + i].mat_le[j] = st[m + i].mat_ri[j] = mat[i][j];
      if (mat[i][j] == mat[i][j - 1])
        st[m + i].left[j] = st[m + i].right[j] = cnt;
      else
        st[m + i].left[j] = st[m + i].right[j] = ++cnt;
    }
    st[m + i].ans = st[m + i].left[n - 1] - st[m + i].left[0] + 1;
  }
  for (int t = m - 1; t > 0; t--) st[t] = combine(st[t << 1], st[t << 1 | 1]);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", query(l - 1, r - 1).ans);
  }
  return 0;
}
