#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int> > v(n, vector<int>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> v[i][j];
  int ans = 0;
  vector<pair<int, int> > c;
  if (!k)
    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j < m; j++) {
        bool flag = 0;
        for (int k = 0; k < n; k++) {
          if (v[k][i] > v[k][j]) {
            flag = 1;
            swap(v[k][i], v[k][j]);
          }
        }
        if (flag) c.push_back((make_pair(i + 1, j + 1)));
      }
    }
  else {
    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j < m; j++) {
        bool flag = 0;
        for (int k = 0; k < n; k++) {
          if (v[k][i] < v[k][j]) {
            flag = 1;
            swap(v[k][i], v[k][j]);
          }
        }
        if (flag) c.push_back((make_pair(j + 1, i + 1)));
      }
    }
  }
  cout << c.size() << endl;
  for (int i = 0; i < c.size(); i++)
    cout << c[i].first << " " << c[i].second << endl;
}
