#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, k;
  cin >> n >> m >> k;
  long long int temp;
  vector<vector<long long int>> v1(n, vector<long long int>(m, 0));
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> temp;
      v1[i][j] = temp;
    }
  }
  long long int hold;
  vector<pair<long long int, long long int>> finans;
  for (long long i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      for (long long int h = j + 1; h < m; h++) {
        if (k == 0 && v1[i][j] > v1[i][h]) {
          for (long long int s = 0; s < n; s++) {
            if (v1[s][j] > v1[s][h]) {
              hold = v1[s][j];
              v1[s][j] = v1[s][h];
              v1[s][h] = hold;
            }
          }
          finans.push_back(make_pair(j + 1, h + 1));
        } else if (k == 1 && v1[i][j] < v1[i][h]) {
          for (long long int s = 0; s < n; s++) {
            if (v1[s][j] < v1[s][h]) {
              hold = v1[s][j];
              v1[s][j] = v1[s][h];
              v1[s][h] = hold;
            }
          }
          finans.push_back(make_pair(h + 1, j + 1));
        }
      }
    }
  }
  cout << finans.size() << endl;
  for (long long int i = 0; i < finans.size(); i++) {
    cout << finans[i].first << " " << finans[i].second << endl;
  }
}
