#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  int a[2000][200];
  int b[10004];
  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]);
  if (k == 0) {
    int sum = 0;
    int q = 0;
    int sign = 0;
    for (int i = 1; i < m; i++) {
      for (int j = i + 1; j <= m; j++) {
        for (int w = 1; w <= n; w++)
          if (a[w][i] > a[w][j]) {
            swap(a[w][i], a[w][j]);
            sign = 1;
          }
        if (sign == 1) {
          b[q++] = i;
          b[q++] = j;
          sum++;
          sign = 0;
        }
      }
    }
    printf("%d\n", sum);
    for (int i = 0; i < q; i += 2) printf("%d %d\n", b[i], b[i + 1]);
  } else {
    int sum = 0;
    int q = 0;
    int sign = 0;
    for (int i = 1; i < m; i++) {
      for (int j = i + 1; j <= m; j++) {
        for (int w = 1; w <= n; w++)
          if (a[w][i] < a[w][j]) {
            swap(a[w][i], a[w][j]);
            sign = 1;
          }
        if (sign == 1) {
          b[q++] = j;
          b[q++] = i;
          sum++;
          sign = 0;
        }
      }
    }
    printf("%d\n", sum);
    for (int i = 0; i < q; i += 2) printf("%d %d\n", b[i], b[i + 1]);
  }
  return 0;
}
