#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
int n; cin>>n;
vector<pair<int,int>>v(n);
map<int,int>mp,pos;
for(int i=0;i<n;i++){
int a,b; cin>>a>>b;
v[i]={a,b};
int x=(a+b)%(2*n);
if(x%2!=0) mp[x]++;
pos[a]=i;
pos[b]=i;
}
int maxi=0,s;
for(auto x: mp){
maxi=max(maxi,x.second);
if(maxi==x.second) s=x.first;
}
cout<<n-maxi<<"\n";
if(maxi==0) s=2*n-1;
vector<bool>c(n,0);
for(int i=0;i<n;i++){
int a=v[i].first, b=v[i].second;
if((a+b)%(2*n)==s) c[i]=1;
}
for (int i=0;i<n;i++) {
if(c[i]) continue;
int a=v[i].first;
while((v[pos[a]].first+v[pos[a]].second)%(2*n)!=s) {
int ant;
if(v[pos[a]].first==a) ant=v[pos[a]].second;
else ant=v[pos[a]].first;
int b=(s-a+2*n)%(2*n);
cout<<pos[a]<<" "<<ant<<" "<<b<<"\n";
v[pos[a]]={a,b};
c[pos[a]]=true;
a=b;
}
}
}
int main(){
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
solve();
return 0;
}