#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int a[N][N];
vector<pair<int, int>> ans;
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  int cnt = 1;
  while (1) {
    int pos1, pos2;
    pos1 = pos2 = -1;
    for (int i = 1; i <= m && pos1 == -1; i++) {
      for (int j = i + 1; j <= m; j++) {
        if (k == 0 && a[cnt][i] > a[cnt][j]) {
          pos1 = i, pos2 = j;
          break;
        }
        if (k == 1 && a[cnt][i] < a[cnt][j]) {
          pos1 = i, pos2 = j;
          break;
        }
      }
    }
    if (pos1 == -1) {
      ++cnt;
      if (cnt == n + 1) break;
      continue;
    }
    if (k == 0)
      ans.push_back(make_pair(pos1, pos2));
    else
      ans.push_back(make_pair(pos2, pos1));
    for (int i = cnt; i <= n; i++) {
      if (a[i][pos1] > a[i][pos2] && k == 0) swap(a[i][pos1], a[i][pos2]);
      if (a[i][pos1] < a[i][pos2] && k == 1) swap(a[i][pos1], a[i][pos2]);
    }
  }
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)ans.size(); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
}
