#include <bits/stdc++.h>
using namespace std;
int a[100000][10];
int n, m, q, nn;
int ans[1 << 18], dif[1 << 18], col[1 << 18][20], le[1 << 18], ri[1 << 18];
const int off = 1 << 17;
int par[40], ra[40];
void dsuInit(int n) {
  for (int i = 0; i < (int)(n); ++i) par[i] = i, ra[i] = 1;
}
inline int dsuParent(int v) {
  if (v == par[v]) return v;
  return par[v] = dsuParent(par[v]);
}
bool dsuMerge(int u, int v) {
  u = dsuParent(u);
  v = dsuParent(v);
  if (u == v) return false;
  if (ra[u] < ra[v]) swap(u, v);
  par[v] = u;
  ra[u] += ra[v];
  return true;
}
int b[20], c[20];
int ma[40];
void stMerge(int l, int r, int res) {
  for (int i = 0; i < (int)(nn); ++i) {
    b[i] = col[l][i];
    c[i] = col[r][i] + dif[l];
  }
  dsuInit(dif[l] + dif[r]);
  ans[res] = ans[l] + ans[r];
  for (int i = 0; i < (int)(n); ++i) {
    if (a[ri[l]][i] == a[le[r]][i]) {
      ans[res] -= dsuMerge(b[n + i], c[i]);
    }
  }
  memset(ma, -1, sizeof ma);
  dif[res] = 0;
  for (int i = 0; i < (int)(n); ++i) {
    int cur = dsuParent(b[i]);
    if (ma[cur] == -1) {
      ma[cur] = dif[res]++;
    }
    col[res][i] = ma[cur];
  }
  for (int i = 0; i < (int)(n); ++i) {
    int cur = dsuParent(c[n + i]);
    if (ma[cur] == -1) {
      ma[cur] = dif[res]++;
    }
    col[res][n + i] = ma[cur];
  }
  le[res] = le[l];
  ri[res] = ri[r];
}
void stBuild() {
  for (int i = 0; i < (int)(m); ++i) {
    int cnt = 1;
    col[off + i][0] = 0;
    for (int j = 1; j < n; ++j) {
      if (a[i][j] == a[i][j - 1]) {
        col[off + i][j] = col[off + i][j - 1];
      } else {
        col[off + i][j] = cnt++;
      }
    }
    for (int j = 0; j < (int)(n); ++j) {
      col[off + i][n + j] = col[off + i][j];
    }
    le[off + i] = ri[off + i] = i;
    ans[off + i] = dif[off + i] = cnt;
  }
  for (int i = off - 1; i >= 1; --i) {
    stMerge(2 * i, 2 * i + 1, i);
  }
}
bool flag;
void stGet(int v, int L, int R, int l, int r) {
  if (l > r) return;
  if (L == l && R == r) {
    if (flag) {
      stMerge(0, v, 0);
    } else {
      ans[0] = ans[v];
      dif[0] = dif[v];
      le[0] = le[v];
      ri[0] = ri[v];
      for (int i = 0; i < (int)(nn); ++i) {
        col[0][i] = col[v][i];
      }
      flag = true;
    }
    return;
  }
  int mid = (L + R) >> 1;
  stGet(2 * v, L, mid, l, min(r, mid));
  stGet(2 * v + 1, mid + 1, R, max(l, mid + 1), r);
}
const int DEBUG = 0;
mt19937 mt(123);
int main() {
  if (DEBUG) {
    n = 10, m = 100000, q = 100000;
    for (int i = 0; i < (int)(n); ++i)
      for (int j = 0; j < (int)(m); ++j) {
        a[j][i] = mt() % 1000000;
      }
  } else {
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 0; i < (int)(n); ++i)
      for (int j = 0; j < (int)(m); ++j) {
        scanf("%d", a[j] + i);
      }
  }
  nn = 2 * n;
  stBuild();
  for (int i = 0; i < (int)(q); ++i) {
    int from, to;
    if (DEBUG) {
      from = mt() % m;
      to = mt() % m;
      if (from > to) {
        swap(from, to);
      }
    } else {
      scanf("%d%d", &from, &to);
      --from, --to;
    }
    flag = false;
    stGet(1, 0, off - 1, from, to);
    assert(flag);
    printf("%d\n", ans[0]);
  }
  return 0;
}
