#include <bits/stdc++.h>
using namespace std;
int n, m, q;
unordered_map<int, pair<int, int>> h;
struct E {
  vector<pair<int, int>> parent_rank;
  E() { parent_rank.resize(1000000 + 1, {-1, -1}); }
  vector<int> last;
  void make_set(int v) {
    parent_rank[v].first = v;
    parent_rank[v].second = 0;
    last.push_back(v);
  }
  void clear() {
    for (int i = 0; i < last.size(); ++i) {
      parent_rank[last[i]] = {-1, -1};
    }
    last.clear();
  }
  int find_set(int v) {
    if (parent_rank[v].first == -1) return -1;
    if (v == parent_rank[v].first) return v;
    return parent_rank[v].first = find_set(parent_rank[v].first);
  }
  bool union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
      if (parent_rank[a].second < parent_rank[b].second) swap(a, b);
      parent_rank[b].first = a;
      if (parent_rank[a].second == parent_rank[b].second)
        ++parent_rank[a].second;
      return true;
    }
    return false;
  }
};
struct S {
  S() : count(0) {
    for (int i = 0; i < n; ++i) c1[i] = c2[i] = {0, 0};
  }
  int count;
  pair<int, int> c1[11], c2[11];
};
struct Tree {
  Tree(S &s, int x1, int x2, Tree *t1, Tree *t2)
      : s(s), x1(x1), x2(x2), t1(t1), t2(t2) {}
  Tree *t1, *t2;
  S s;
  int x1, x2;
};
vector<pair<int, int>> c;
E e;
S Combine(const vector<vector<int>> &data, const S &a, const S &b) {
  S ret;
  e.clear();
  for (int i = 0; i < n; ++i) {
    e.make_set(a.c2[i].first);
    e.make_set(b.c1[i].first);
  }
  int merged = 0;
  for (int i = 0; i < n; ++i) {
    if (a.c2[i].second == b.c1[i].second && a.c2[i].first != b.c1[i].first) {
      if (e.union_sets(a.c2[i].first, b.c1[i].first)) ++merged;
    }
  }
  for (int i = 0; i < n; ++i) {
    ret.c1[i] = a.c1[i];
    ret.c2[i] = b.c2[i];
    int f = e.find_set(ret.c1[i].first);
    if (f != -1 && f != ret.c1[i].first) ret.c1[i].first = f;
    f = e.find_set(ret.c2[i].first);
    if (f != -1 && f != ret.c2[i].first) ret.c2[i].first = f;
  }
  ret.count = a.count + b.count - merged;
  return ret;
}
Tree *rec(vector<vector<int>> &data, int x1, int x2) {
  assert(x2 >= x1);
  if (x1 == x2) {
    S ret;
    for (int i = 0; i < n; ++i) {
      assert(x1 < 100000);
      ret.c1[i] = ret.c2[i] = {i * 100000 + x1, data[i][x1]};
      if (i > 0 && ret.c1[i].second == ret.c1[i - 1].second)
        ret.c1[i] = ret.c2[i] = ret.c1[i - 1];
      else
        ++ret.count;
    }
    return new Tree(ret, x1, x2, nullptr, nullptr);
  }
  Tree *t1 = rec(data, x1, (x1 + x2) / 2);
  Tree *t2 = rec(data, (x1 + x2) / 2 + 1, x2);
  S a = t1->s;
  S b = t2->s;
  S ret = Combine(data, a, b);
  return new Tree(ret, x1, x2, t1, t2);
}
bool Inter(int a1, int a2, int b1, int b2) {
  return (b1 <= a1 && a1 <= b2) || (b1 <= a2 && a2 <= b2) ||
         (a1 <= b1 && b1 <= a2) || (a1 <= b2 && b2 <= a2);
}
unordered_map<long long, S> dp;
int C = 0;
S rec3(vector<vector<int>> &data, Tree *t, int x1, int x2) {
  ++C;
  if (x1 <= t->x1 && t->x2 <= x2) {
    return t->s;
  }
  S a;
  S b;
  if (Inter(x1, x2, t->t1->x1, t->t1->x2))
    a = rec3(data, t->t1, x1, min(x2, t->t1->x2));
  if (Inter(x1, x2, t->t2->x1, t->t2->x2))
    b = rec3(data, t->t2, max(x1, t->t2->x1), x2);
  if (a.count == 0) {
    assert(b.count != 0);
    return b;
  }
  if (b.count == 0) {
    assert(a.count != 0);
    return a;
  }
  S ret = Combine(data, a, b);
  return ret;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n >> m >> q;
  vector<vector<int>> data(n, vector<int>(m));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> data[i][j];
  Tree *t = rec(data, 0, m - 1);
  for (int i = 0; i < q; ++i) {
    int x1, x2;
    cin >> x1 >> x2;
    --x1;
    --x2;
    C = 0;
    S res = rec3(data, t, x1, x2);
    cout << res.count << endl;
  }
  return 0;
}
