#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void chmin(T &t, U f) {
  if (t > f) t = f;
}
template <class T, class U>
void chmax(T &t, U f) {
  if (t < f) t = f;
}
signed main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) {
      int a;
      cin >> a;
    }
  cout << m * (m - 1) / 2 << endl;
  for (int i = 0; i < (m); i++)
    for (int j = (i + 1); j < (m); j++) {
      if (k == 0)
        cout << i + 1 << " " << j + 1 << endl;
      else
        cout << m - i << " " << m - j << endl;
    }
  return 0;
}
