#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
struct point {
  long long x, y;
  point (long long x, long long y) : x(x), y(y) {}
  point () {}
  point operator - (point p) const {
    return point(x - p.x, y - p.y);
  }
  long long operator * (point p) const {
    return x * p.y - y * p.x;
  }
} a[maxn];
int idx[maxn];
int cyc[maxn];

int main() {  
  int n;
  cin >> n;
  vector <int> ord;
  int piv = -1;
  for(int i = 1; i <= n; ++i) {
    cin >> a[i].x >> a[i].y >> idx[i];
    if(idx[i] != i) {
      ord.push_back(i);
      if(piv == -1 || a[piv].x < a[i].x) piv = i;
    }
  }
  if(piv == -1) {
    cout << 0 << endl;
    exit(0);
  }
  ord.erase(find(ord.begin(), ord.end(), piv));
  sort(ord.begin(), ord.end(), [&] (int i, int j) {
      return (a[i] - a[piv]) * (a[j] - a[piv]) > 0; });
  vector <pair <int, int>> swaps;
  auto move = [&] (int i, int j) {
    swaps.emplace_back(i, j);
    swap(idx[i], idx[j]);
  };
  for(int x = 0; x < ord.size(); x++) {
    int i = ord[x];
    if(cyc[i] == 0) {
      while(cyc[i] == 0) {
        cyc[i] = true;
        i = idx[i];
      }
      if(x) {
        move(ord[x - 1], ord[x]);
      }
    }
  }
  for(int i : ord) {
    move(piv, idx[piv]);
  }
  cout << swaps.size() << endl;
  for(auto i : swaps) cout << i.first << " " << i.second << endl;
  return 0;
}
