#include <bits/stdc++.h>
using namespace std;
int n, m, b, a[1111][111];
int main() {
  scanf("%d%d%d", &n, &m, &b);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) scanf("%d", a[i] + j);
  vector<pair<int, int> > ans;
  for (int i = 0; i < m; ++i)
    for (int j = i + 1; j < m; ++j) {
      if (b)
        ans.push_back({j, i});
      else
        ans.push_back({i, j});
    }
  sort(ans.begin(), ans.end());
  ans.resize(unique(ans.begin(), ans.end()) - ans.begin());
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); ++i)
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
  return 0;
}
