#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <class T>
using vec = std::vector<T>;
template <class T>
using vec2d = std::vector<std::vector<T>>;
template <class T>
vec2d<T> makeVec2d(const int n1) {
  return vec2d<T>(n1);
}
bool __hack = std::ios::sync_with_stdio(false);
auto __hack1 = cin.tie(nullptr);
template <class T>
void subOne(vec<T>& v) {
  for_each(v.begin(), v.end(), [](T& el) { --el; });
}
struct Input {
  Input(istream& in) : in(&in) {}
  template <class T>
  T next() const {
    T x;
    *in >> x;
    return x;
  }
  int ni() const { return next<int>(); }
  template <class T>
  vec<T> nVec(int n) const {
    vec<T> v(n);
    for (int i = 0; i < n; ++i) {
      v[i] = next<T>();
    }
    return v;
  }
  vec<int> nvi(int n) const { return nVec<int>(n); }
  istream* in;
};
Input in(cin);
class Output {
 private:
  ostream* out;
  template <typename T>
  void printSingle(const T& value) {
    *out << value;
  }

 public:
  Output(ostream& out) : out(&out) {}
  inline void print() {}
  template <typename T, typename... Ts>
  inline void print(const T& f, const Ts&... args) {
    printSingle(f);
    if (sizeof...(args) != 0) {
      *out << ' ';
      print(args...);
    }
  }
  template <typename... Ts>
  inline void println(const Ts&... args) {
    print(args...);
    *out << '\n';
  }
  template <typename... Ts>
  inline void operator()(const Ts&... args) {
    println(args...);
  }
};
Output out(cout);
namespace template_util {
constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }
template <int N>
struct bytetype {};
template <uint64_t N>
struct minimal_uint : bytetype<bytecount(N)> {};
}  // namespace template_util
namespace dsu {
struct DSU {
  vector<int> parent;
  vector<int> rank;
  vector<int> size;
  DSU(int n) {
    parent = vector<int>(n, 0);
    rank = vector<int>(n, 0);
    size = vector<int>(n, 1);
    for (int i = 0; i < (n); ++i) {
      parent[i] = i;
    }
  }
  void resetOne(int i) {
    parent[i] = i;
    rank[i] = 0;
    size[i] = 1;
  }
  bool unite(int a, int b) {
    a = findSet(a);
    b = findSet(b);
    if (a == b) {
      return false;
    }
    int size_a = size[a];
    int size_b = size[b];
    if (rank[a] >= rank[b]) {
      ++rank[b];
      parent[b] = a;
    } else {
      parent[a] = b;
    }
    size[findSet(a)] = size_a + size_b;
    return true;
  }
  int findSet(int v) {
    return (v == parent[v]) ? v : (parent[v] = findSet(parent[v]));
  }
};
}  // namespace dsu
vec<int> getColumn(const vec2d<int>& a, int col) {
  vec<int> res(a.size());
  for (int i = 0; i < (a.size()); ++i) {
    res[i] = a[i][col];
  }
  return res;
}
vec2d<int> a;
dsu::DSU* localDsu;
struct SegmentTree {
  struct Node {
    int cc;
    int l, r;
    vec<int> leftProfile, rightProfile;
    explicit Node() {
      cc = -1;
      leftProfile.clear();
      rightProfile.clear();
    }
    explicit Node(int id, const vec<int>& v) {
      l = id;
      r = id;
      leftProfile.clear();
      rightProfile.clear();
      cc = (int)v.size();
      int cur = 1;
      leftProfile.push_back(cur);
      for (int i = (1); i <= ((int)v.size() - 1); ++i) {
        if (v[i] == v[i - 1]) {
          --cc;
        } else {
          ++cur;
        }
        leftProfile.push_back(cur);
      }
      rightProfile = leftProfile;
    }
    Node(const Node& l, const Node& r) {
      this->l = l.l;
      this->r = r.r;
      cc = l.cc + r.cc;
      int curN = static_cast<int>(l.leftProfile.size());
      for (int i = 0; i < (curN * 4); ++i) {
        localDsu->resetOne(i);
      }
      for (int i = 0; i < (curN); ++i) {
        for (int j = 0; j < (curN); ++j) {
          if (l.leftProfile[i] == l.rightProfile[j]) {
            localDsu->unite(i, j + curN);
          }
          if (j < i && l.leftProfile[i] == l.leftProfile[j]) {
            localDsu->unite(i, j);
          }
          if (j < i && l.rightProfile[i] == l.rightProfile[j]) {
            localDsu->unite(curN + i, curN + j);
          }
          if (r.leftProfile[i] == r.rightProfile[j]) {
            localDsu->unite(i + curN * 2, j + curN * 3);
          }
          if (j < i && r.leftProfile[i] == r.leftProfile[j]) {
            localDsu->unite(i + curN * 2, j + curN * 2);
          }
          if (j < i && r.rightProfile[i] == r.rightProfile[j]) {
            localDsu->unite(curN * 3 + i, curN * 3 + j);
          }
        }
      }
      for (int i = 0; i < (curN); ++i) {
        if (a[i][l.r] == a[i][r.l]) {
          if (localDsu->unite(i + curN, i + 2 * curN)) {
            --cc;
          }
        }
      }
      leftProfile = vec<int>(curN, -1);
      rightProfile = vec<int>(curN, -1);
      for (int i = 0; i < (curN); ++i) {
        leftProfile[i] = localDsu->findSet(i);
      }
      for (int i = 0; i < (curN); ++i) {
        rightProfile[i] = localDsu->findSet(3 * curN + i);
      }
    }
  };
  int n;
  vec<Node> tree;
  SegmentTree(int n) : n(n) {
    tree = vec<Node>(4 * n);
    build(1, 0, n);
  }
  void build(int v, int l, int r) {
    if (l + 1 == r) {
      tree[v] = Node(l, getColumn(a, l));
      return;
    }
    int e = (l + r) / 2;
    build(v * 2, l, e);
    build(v * 2 + 1, e, r);
    tree[v] = Node(tree[2 * v], tree[2 * v + 1]);
  }
  Node internalGet(int l, int r, int v, int vl, int vr) {
    if (l >= vr || vl >= r) return Node();
    if (vl >= l && vr <= r) {
      return tree[v];
    }
    int vm = (vl + vr) / 2;
    Node lNode = internalGet(l, r, 2 * v, vl, vm);
    Node rNode = internalGet(l, r, 2 * v + 1, vm, vr);
    if (lNode.cc == -1) return rNode;
    if (rNode.cc == -1) return lNode;
    return {lNode, rNode};
  }
  int get(int l, int r) { return internalGet(l, r, 1, 0, n).cc; }
};
void solve(istream& inStream, ostream& outStream) {
  in = Input(inStream);
  out = Output(outStream);
  auto n = in.ni();
  auto m = in.ni();
  auto q = in.ni();
  a = makeVec2d<int>(n);
  localDsu = new dsu::DSU(n * 4);
  for (int i = 0; i < (n); ++i) {
    a[i] = in.nvi(m);
    subOne(a[i]);
  }
  SegmentTree stree(m);
  while (q--) {
    auto l = in.ni() - 1;
    auto r = in.ni() - 1;
    out(stree.get(l, r + 1));
  }
}
int main() {
  solve(cin, cout);
  return 0;
}
