#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1111;
int t[MAXN][MAXN];
vector<pair<int, int> > V;
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) scanf("%d", &t[i][j]);
    if (k == 1) reverse(t[i] + 1, t[i] + m + 1);
  }
  printf("%d\n", (m * (m - 1)) / 2);
  if (k == 0) {
    for (int i = 1; i <= m; i++)
      for (int j = i + 1; j <= m; j++) printf("%d %d\n", i, j);
  } else {
    for (int i = 1; i <= m; i++)
      for (int j = i + 1; j <= m; j++) printf("%d %d\n", j, i);
  }
}
