#include <bits/stdc++.h>
using namespace std;
bool isSorted(const vector<int>& a, int n, int k) {
  for (int i = 0; i < n - 1; i++) {
    if ((k == 0) && (a[i] > a[i + 1])) return false;
    if ((k == 1) && (a[i] < a[i + 1])) return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m, k, v;
  cin >> n >> m >> k;
  vector<int> a[1001];
  set<pair<int, int> > ans;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> v;
      a[i].push_back(v);
    }
  }
  for (int i = 0; i < n; i++) {
    if (isSorted(a[i], m, k)) continue;
    for (int j1 = 0; j1 < m; j1++) {
      for (int j2 = j1 + 1; j2 < m; j2++) {
        if (k == 0 && a[i][j1] > a[i][j2]) ans.insert(make_pair(j1, j2));
        if (k == 1 && a[i][j1] < a[i][j2]) ans.insert(make_pair(j2, j1));
      }
    }
  }
  int cnt = static_cast<int>(ans.size());
  cout << cnt;
  if (cnt > 0) {
    cout << "\n";
    for (auto i : ans) {
      cout << i.first + 1 << " " << i.second + 1 << "\n";
    }
  }
  return 0;
}
