#include <bits/stdc++.h>
using namespace std;
int a[1000][1000];
int n, m, k;
void swapColumns(const int &i, const int &j) {
  if (i < j) {
    for (int q = 0; q < n; ++q) {
      if ((a[q][i] > a[q][j]) && (k == 0))
        swap(a[q][i], a[q][j]);
      else if ((a[q][i] < a[q][j]) && (k == 1))
        swap(a[q][i], a[q][j]);
    }
  } else {
    for (int q = 0; q < n; ++q) {
      if ((a[q][j] > a[q][i]) && (k == 0))
        swap(a[q][i], a[q][j]);
      else if ((a[q][j] < a[q][i]) && (k == 1))
        swap(a[q][i], a[q][j]);
    }
  }
}
int isSorted() {
  for (int q = 0; q < n; ++q) {
    for (int j = 1; j < m; ++j) {
      if ((a[q][j] < a[q][j - 1]) && (k == 0))
        return 0;
      else if ((a[q][j] > a[q][j - 1]) && (k == 1))
        return 0;
    }
  }
  return 1;
}
int main(int argc, char *argv[]) {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
    }
  }
  vector<pair<int, int>> vp;
  if (k == 0) {
    while (!isSorted()) {
      for (int i = 0; i < m; ++i) {
        for (int j = i + 1; j < m; ++j) {
          swapColumns(i, j);
          pair<int, int> pii;
          pii.first = i;
          pii.second = j;
          vp.push_back(pii);
        }
      }
    }
  } else {
    while (!isSorted()) {
      for (int i = m - 1; i >= 0; --i) {
        for (int j = i - 1; j >= 0; --j) {
          swapColumns(i, j);
          pair<int, int> pii;
          pii.first = i;
          pii.second = j;
          vp.push_back(pii);
        }
      }
    }
  }
  printf("%d\n", vp.size());
  for (vector<pair<int, int>>::iterator i = vp.begin(); i != vp.end(); ++i)
    printf("%d %d\n", (*i).first + 1, (*i).second + 1);
  return 0;
}
