#include <bits/stdc++.h>
using namespace std;
const int INF = 0xfffffff;
int n, m, kk;
int num[1005][105];
int leftt[10000], rightt[10000];
int main() {
  scanf("%d%d%d", &n, &m, &kk);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &num[i][j]);
  int cnt = 0;
  for (int i = 1; i < m; i++) {
    for (int j = i + 1; j <= m; j++) {
      bool change = false;
      for (int k = 1; k <= n; k++) {
        if (!kk && num[k][i] > num[k][j]) {
          swap(num[k][i], num[k][j]);
          change = true;
        } else if (kk && num[k][i] < num[k][j]) {
          change = true;
          swap(num[k][i], num[k][j]);
        }
      }
      if (change) {
        leftt[cnt] = i;
        rightt[cnt++] = j;
      }
    }
  }
  printf("%d\n", cnt);
  for (int i = 0; i < cnt; i++) {
    if (!kk)
      printf("%d %d\n", leftt[i], rightt[i]);
    else
      printf("%d %d\n", rightt[i], leftt[i]);
  }
  return 0;
}
