#include <bits/stdc++.h>
using namespace std;
template <typename T>
T power(T a, int n, int mod) {
  T res = 1;
  while (n) {
    if (n % 2 == 1) res = (res * a) % mod;
    n /= 2;
    a = (a * a) % mod;
  }
  return res;
}
int arr[1002][102];
vector<int> a, b;
int main() {
  int n;
  int m;
  bool k;
  int t;
  bool flag;
  cin >> n >> m >> k;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      cin >> arr[i][j];
    }
  }
  int c = 0;
  int i, j;
  for (int i = 1; i < m + 1; i++) {
    for (int j = (i + 1); j < m + 1; j++) {
      flag = 0;
      for (int p = 1; p < n + 1; p++) {
        if (k) {
          if (arr[p][j] > arr[p][i]) {
            t = arr[p][j];
            arr[p][j] = arr[p][i];
            arr[p][i] = t;
            flag = 1;
          }
        } else {
          if (arr[p][j] < arr[p][i]) {
            t = arr[p][j];
            arr[p][j] = arr[p][i];
            arr[p][i] = t;
            flag = 1;
          }
        }
      }
      if (k) {
        if (flag) {
          a.push_back(j);
          b.push_back(i);
        }
      } else {
        if (flag) {
          a.push_back(i);
          b.push_back(j);
        }
      }
    }
  }
  cout << a.size() << endl;
  for (int l = 0; l < a.size(); l++) {
    printf("%d %d\n", a[l], b[l]);
  }
  return 0;
}
