#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, t, l, m, n, a[1010][1010];
  vector<pair<int, int> > pos1;
  scanf("%d %d %d", &n, &m, &t);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  if (t == 0) {
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        for (k = j + 1; k < m; k++) {
          if (a[i][j] > a[i][k]) {
            pair<int, int> f1;
            f1 = make_pair(j, k);
            pos1.push_back(f1);
            for (l = 0; l < n; l++) {
              if (a[l][j] > a[l][k]) {
                int temp = a[l][j];
                a[l][j] = a[l][k];
                a[l][k] = temp;
              }
            }
          }
        }
      }
    }
  } else if (t == 1) {
    for (i = 0; i < n; i++) {
      for (j = m - 1; j >= 0; j--) {
        for (k = j - 1; k >= 0; k--) {
          if (a[i][j] > a[i][k]) {
            pair<int, int> f1;
            f1 = make_pair(j, k);
            pos1.push_back(f1);
            for (l = 0; l < n; l++) {
              if (a[l][j] > a[l][k]) {
                int temp = a[l][j];
                a[l][j] = a[l][k];
                a[l][k] = temp;
              }
            }
          }
        }
      }
    }
  }
  int g = pos1.size();
  printf("%d\n", g);
  for (i = 0; i < pos1.size(); i++) {
    printf("%d %d\n", pos1[i].first + 1, pos1[i].second + 1);
  }
  return 0;
}
