#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 100;
const int INF = 1000 * 1000 * 1000;
int n, m, k, a[MAXN][MAXN];
vector<pair<int, int> > ans;
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> a[i][j];
  for (int l = 1; l < m; ++l)
    for (int r = l + 1; r <= m; ++r) {
      int cnt = 0;
      for (int i = 1; i <= n; ++i) {
        if (k == 0 && a[i][r] < a[i][l]) cnt++;
        if (k == 1 && a[i][r] > a[i][l]) cnt++;
      }
      if (cnt >= 1) {
        ans.push_back(make_pair(l, r));
        for (int i = 1; i <= n; ++i) {
          if (k == 0 && a[i][l] > a[i][r]) swap(a[i][r], a[i][l]);
          if (k == 1 && a[i][l] < a[i][r]) swap(a[i][r], a[i][l]);
        }
      }
    }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i) {
    if (k == 0)
      cout << ans[i].first << " " << ans[i].second << endl;
    else
      cout << ans[i].second << " " << ans[i].first << endl;
  }
  return 0;
}
