#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000][100], k;
vector<pair<int, int> > sol;
void calc0(int at) {
  for (int i = 0; i < m; ++i) {
    int mn = i;
    for (int j = i + 1; j < m; ++j)
      if (a[at][j] < a[at][mn]) mn = j;
    if (mn == i) continue;
    sol.push_back(make_pair(i + 1, mn + 1));
    for (int j = 0; j < n; ++j)
      if (a[j][i] > a[j][mn]) swap(a[j][i], a[j][mn]);
  }
}
void calc1(int at) {
  for (int i = 0; i < m; ++i) {
    int mx = i;
    for (int j = i + 1; j < m; ++j)
      if (a[at][j] > a[at][mx]) mx = j;
    if (mx == i) continue;
    sol.push_back(make_pair(mx + 1, i + 1));
    for (int j = 0; j < n; ++j)
      if (a[j][mx] > a[j][i]) swap(a[j][i], a[j][mx]);
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) scanf("%d", &a[i][j]);
  for (int i = 0; i < n; ++i)
    if (k == 0)
      calc0(i);
    else
      calc1(i);
  printf("%d\n", (int)sol.size());
  for (size_t i = 0; i < sol.size(); ++i)
    printf("%d %d\n", sol[i].first, sol[i].second);
  return 0;
}
