#include <bits/stdc++.h>
using namespace std;
int n, m, k, i, j, l, hooh[1001][101], col;
bool check;
struct beallyjean {
  int lol1;
  int lol2;
};
beallyjean asnwer[10011];
int main() {
  cin >> n >> m >> k;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> hooh[i][j];
  if (k == 0) {
    for (i = 1; i <= m; i++)
      for (j = i + 1; j <= m; j++) {
        check = false;
        for (l = 1; l <= n; l++)
          if (hooh[l][i] > hooh[l][j]) {
            swap(hooh[l][i], hooh[l][j]);
            check = true;
          }
        if (check) {
          asnwer[++col].lol1 = i;
          asnwer[col].lol2 = j;
        }
      }
  } else {
    for (i = 1; i <= m; i++)
      for (j = i + 1; j <= m; j++) {
        check = false;
        for (l = 1; l <= n; l++)
          if (hooh[l][i] < hooh[l][j]) {
            swap(hooh[l][i], hooh[l][j]);
            check = true;
          }
        if (check) {
          asnwer[++col].lol1 = j;
          asnwer[col].lol2 = i;
        }
      }
  }
  cout << col << endl;
  for (i = 1; i <= col; i++)
    cout << asnwer[i].lol1 << " " << asnwer[i].lol2 << endl;
  return 0;
}
