#include <bits/stdc++.h>
using namespace std;
const int N = 50010;
int rec[1010][111];
int ans[10000][2];
int main() {
  int n, m, k, cnt;
  while (cin >> n >> m >> k) {
    cnt = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) scanf("%d", rec[i] + j);
    for (int i = 0; i < m; i++)
      for (int j = i + 1; j < m; j++) {
        bool op = 0;
        int x, y;
        for (int h = 0; h < n; h++)
          if (k && rec[h][i] < rec[h][j]) {
            x = j;
            y = i;
            op = 1;
            rec[h][i] ^= rec[h][j];
            rec[h][j] ^= rec[h][i];
            rec[h][i] ^= rec[h][j];
          } else if (!k && rec[h][i] > rec[h][j]) {
            op = 1;
            x = i;
            y = j;
            rec[h][i] ^= rec[h][j];
            rec[h][j] ^= rec[h][i];
            rec[h][i] ^= rec[h][j];
          }
        if (op) {
          ans[cnt][0] = x + 1, ans[cnt++][1] = y + 1;
        }
      }
    printf("%d\n", cnt);
    for (int i = 0; i < cnt; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  }
  return 0;
}
