//EGOI 2025 A String Problem
//https://qoj.ac/contest/2344/problem/13169
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
int main(){
ll n, a, b, ans;
cin >> n;
vll tot(2*n,0), to(2*n), id(2*n);
for(int i=0; i<n; i++){
cin >> a >> b;
to[a]=b; to[b]=a; id[a]=id[b]=i;
}
for(int i=0; i<2*n; i++) if((i+to[i])%2==1) tot[(i+to[i])%(2*n)]++;
ans=max_element(tot.begin(),tot.end())-tot.begin();
cout << n-tot[ans]/2 << "\n";
if(ans==0) ans=1;
for(int i=0; i<2*n; i++) if((i+to[i])%(2*n)!=ans){
ll cur=i, bst=(ans-cur+2*n)%(2*n); id[to[cur]]=-1;
while(id[bst]!=-1){
cout << id[cur] << " " << to[cur] << " " << bst << "\n";
to[cur]=bst; ll nxt=to[bst]; id[bst]=id[cur]; to[bst]=cur;
cur=nxt; bst=(ans-cur+2*n)%(2*n);
}
cout << id[cur] << " " << to[cur] << " " << bst << "\n";
to[cur]=bst; id[bst]=id[cur]; to[bst]=cur;
}
return 0;
}