#include <bits/stdc++.h>
int s[1010][110];
int record[5000][3];
int main() {
  int n, m, k;
  int i, j, h;
  int temp, ans = 0, flag;
  scanf("%d%d%d", &n, &m, &k);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      scanf("%d", &s[i][j]);
    }
  }
  for (i = 1; i <= m - 1; i++) {
    for (j = i + 1; j <= m; j++) {
      flag = 0;
      for (h = 1; h <= n; h++) {
        if (k == 0 && s[h][i] > s[h][j]) {
          flag = 1;
          temp = s[h][i];
          s[h][i] = s[h][j];
          s[h][j] = temp;
        } else if (k == 1 && s[h][i] < s[h][j]) {
          flag = 1;
          temp = s[h][i];
          s[h][i] = s[h][j];
          s[h][j] = temp;
        }
      }
      if (flag) {
        ans++;
        record[ans][1] = i;
        record[ans][2] = j;
      }
    }
  }
  printf("%d\n", ans);
  for (i = 1; i <= ans; i++) {
    if (k == 0)
      printf("%d %d\n", record[i][1], record[i][2]);
    else
      printf("%d %d\n", record[i][2], record[i][1]);
  }
  return 0;
}
