#include <bits/stdc++.h>
using namespace std;
int v[1005][105];
int vet[105];
int main() {
  int n, m, k;
  int a1[105], a2[105];
  int tmp;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> tmp;
      a1[j] = a2[j] = tmp;
    }
    sort(a2, a2 + m);
    if (!k)
      for (int j = 0; j < m; j++) {
        if (a1[j] == a2[j]) v[i][j] = 1;
      }
    else
      for (int j = 0; j < m; j++) {
        if (a1[j] == a2[m - j - 1]) v[i][j] = 1;
      }
  }
  int cnt = 0, flg;
  for (int j = 0; j < m; j++) {
    flg = 1;
    for (int i = 0; i < n; i++)
      if (0 == v[i][j]) {
        flg = 0;
        break;
      }
    if (flg) {
      cnt++;
      vet[j] = 1;
    }
  }
  cout << ((m - cnt) * (m - cnt - 1) / 2) << endl;
  for (int i = 0; i < m; i++) {
    if (vet[i]) continue;
    for (int j = i + 1; j < m; j++) {
      if (vet[j]) continue;
      if (!k)
        cout << i + 1 << " " << j + 1 << endl;
      else
        cout << j + 1 << " " << i + 1 << endl;
    }
  }
  return 0;
}
