#include <bits/stdc++.h>
using namespace std;
int n, m, k, i, j;
int a[1005][1005];
int xx[10000], yy[10000];
int num = 0;
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  if (k == 0) {
    for (int i = 0; i < n; i++)
      for (int j = m - 1; j >= 0; j--) {
        int now = j;
        for (int j2 = j - 1; j2 >= 0; j2--)
          if (a[i][j2] > a[i][now]) now = j2;
        if (now != j) {
          for (int i2 = i; i2 < n; i2++)
            if (a[i2][now] > a[i2][j]) {
              int temp = a[i2][now];
              a[i2][now] = a[i2][j];
              a[i2][j] = temp;
            }
          xx[num] = now;
          yy[num++] = j;
        }
      }
  } else {
    for (int i = 0; i < n; i++)
      for (int j = 0; j <= m - 1; j++) {
        int now = j;
        for (int j2 = j + 1; j2 <= m - 1; j2++)
          if (a[i][j2] > a[i][now]) now = j2;
        if (now != j) {
          for (int i2 = i; i2 < n; i2++)
            if (a[i2][now] > a[i2][j]) {
              int temp = a[i2][now];
              a[i2][now] = a[i2][j];
              a[i2][j] = temp;
            }
          xx[num] = now;
          yy[num++] = j;
        }
      }
  }
  cout << num << endl;
  for (int i = 0; i < num; i++) cout << xx[i] + 1 << " " << yy[i] + 1 << endl;
}
