#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int a[1001][101];
vector<pair<int, int> > ans;
int all = 0;
void sortUp() {
  for (int u = 1; u <= n; u++)
    for (int i = m; i > 0; i--) {
      int l = 0, jj;
      for (int j = i - 1; j > 0; j--)
        if (a[u][j] > l) l = a[u][j], jj = j;
      if (l != 0 && l > a[u][i]) {
        swap(a[u][i], a[u][jj]);
        for (int ii = 1; ii <= n; ii++)
          if (ii != u && a[ii][i] < a[ii][jj]) swap(a[ii][i], a[ii][jj]);
        ans.push_back(make_pair(jj, i));
      }
    }
}
void sortDown() {
  for (int u = 1; u <= n; u++)
    for (int i = m; i > 0; i--) {
      int l = 1000000000;
      int jj;
      for (int j = i - 1; j > 0; j--)
        if (a[u][j] < l) l = a[u][j], jj = j;
      if (l != 0 && l < a[u][i]) {
        swap(a[u][i], a[u][jj]);
        for (int ii = 1; ii <= n; ii++)
          if (ii != u && a[ii][i] > a[ii][jj]) swap(a[ii][i], a[ii][jj]);
        ans.push_back(make_pair(i, jj));
      }
    }
}
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> a[i][j];
  if (k == 0)
    sortUp();
  else
    sortDown();
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
