#include <bits/stdc++.h>
using namespace std;
const pair<int, int> DD[] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                             {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
template <class T>
T smin(T &a, T b) {
  if (a > b) a = b;
  return a;
}
template <class T>
T smax(T &a, T b) {
  if (a < b) a = b;
  return a;
}
int n, m;
int s[11][1 << 20];
struct seg {
  int g[22];
  int color[22];
  int ans;
  seg(void) {
    ans = n;
    for (int i = 1; i <= n + n; ++i) color[i] = 0;
    for (int i = 1; i <= n; ++i) g[i] = i, g[i + n] = i;
  }
  seg(int index) {
    ans = 0;
    for (int i = 1; i <= n; ++i) color[i] = s[i][index];
    for (int i = n + 1; i <= n + n; ++i) color[i] = color[i - n];
    for (int i = 1; i <= n; ++i)
      if (s[i][index] == s[i - 1][index])
        g[i] = g[i - 1];
      else
        g[i] = ++ans;
    for (int i = n + 1; i <= n + n; ++i) g[i] = g[i - n];
    ans = 0;
  }
  int Answer(void) {
    int answer = ans;
    static int was[55];
    for (int i = 1; i <= n + n; ++i) was[i] = 0;
    for (int i = 1; i <= n + n; ++i) was[g[i]] = 1;
    for (int i = 1; i <= n + n; ++i) answer += was[i];
    return answer;
  }
};
seg t[1 << 20];
seg operator+(seg a, seg b) {
  seg c;
  static int f[55], was[55];
  for (int i = 1; i <= 4 * n; ++i) f[i] = i, was[i] = 0;
  function<int(int)> get = [&](int k) {
    return f[k] == k ? k : f[k] = get(f[k]);
  };
  auto OK = [&](int k) { return k == get(k); };
  for (int i = 1; i <= n + n; ++i) b.g[i] += n + n;
  for (int i = 1; i <= n; ++i)
    if (a.color[i + n] == b.color[i]) f[get(a.g[i + n])] = get(b.g[i]);
  for (int i = 1; i <= n; ++i) c.color[i] = a.color[i];
  for (int i = n + 1; i <= n + n; ++i) c.color[i] = b.color[i];
  c.ans = a.ans + b.ans;
  for (int i = 1; i <= n; ++i) was[get(a.g[i])] = 1;
  for (int i = n + 1; i <= n + n; ++i) was[get(b.g[i])] = 1;
  int cnt = 0;
  for (int i = 1; i <= 4 * n; ++i)
    if (was[i]) was[i] = ++cnt;
  for (int i = 1; i <= n; ++i) c.g[i] = was[get(a.g[i])];
  for (int i = n + 1; i <= n + n; ++i) c.g[i] = was[get(b.g[i])];
  for (int i = n + 1; i <= n + n; ++i)
    if (OK(a.g[i]) && !was[get(a.g[i])]) ++c.ans, was[get(a.g[i])] = -1;
  for (int i = 1; i <= n; ++i)
    if (OK(b.g[i]) && !was[get(b.g[i])]) ++c.ans, was[get(b.g[i])] = -1;
  return c;
}
void build(int p, int u, int node) {
  if (p == u)
    t[node] = seg(p);
  else {
    int mid = (p + u) / 2;
    build(p, mid, node << 1);
    build(mid + 1, u, node << 1 | 1);
    t[node] = t[node << 1] + t[node << 1 | 1];
  }
}
seg query(int p, int u, int l, int r, int node) {
  if (l <= p && u <= r) return t[node];
  int mid = (p + u) / 2;
  if (l <= mid && mid + 1 <= r)
    return query(p, mid, l, r, node << 1) +
           query(mid + 1, u, l, r, node << 1 | 1);
  if (l <= mid) return query(p, mid, l, r, node << 1);
  return query(mid + 1, u, l, r, node << 1 | 1);
}
int main(void) {
  srand(time(0));
  cout << fixed << setprecision(7);
  cerr << fixed << setprecision(7);
  int q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) scanf("%d", &s[i][j]);
  build(1, m, 1);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    cout << query(1, m, l, r, 1).Answer() << '\n';
  }
  cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
       << '\n';
  return 0;
}
