#include <bits/stdc++.h>
using namespace std;
long long a[1001][1001], x[1000000], y[1000000];
int main() {
  long long n, m, t, i, j, l = 0, k, g, i1, j1, u, o = 0, min1, max1;
  cin >> n >> m >> t;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) cin >> a[i][j];
  }
  if (t == 0) {
    for (g = 1; g <= n; g++) {
      for (i = 1; i <= m; i++) {
        min1 = 1000001;
        for (j = i; j <= m; j++) {
          if (min1 > a[g][j]) {
            min1 = a[g][j];
            u = j;
          }
        }
        if (u != i) {
          for (j = 1; j <= n; j++) {
            if (a[j][u] < a[j][i]) swap(a[j][u], a[j][i]);
          }
          o++;
          x[o] = i;
          y[o] = u;
        }
      }
    }
  } else {
    for (g = 1; g <= n; g++) {
      for (i = 1; i <= m; i++) {
        max1 = -1000001;
        for (j = i; j <= m; j++) {
          if (max1 < a[g][j]) {
            max1 = a[g][j];
            u = j;
          }
        }
        if (u != i) {
          for (j = 1; j <= n; j++) {
            if (a[j][u] > a[j][i]) swap(a[j][u], a[j][i]);
          }
          o++;
          x[o] = u;
          y[o] = i;
        }
      }
    }
  }
  cout << o << endl;
  for (i = 1; i <= o; i++) {
    cout << x[i] << ' ' << y[i] << endl;
  }
  return 0;
}
