//MEHNAT
#include<bits/stdc++.h>
using namespace std;
#define tr(c, it) \
for(auto it = c.begin(); it != c.end(); it++)
#define ll long long
//const int MAX=1e3 + 5;
int a[1000][1000];
bool flag=0;
bool adj(int a[][1000],int n){
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
if(a[i][j]==1)
return true;
}
}
return false;
}
int main(){
int n,x,y;
vector<pair <int,pair <int,int> > > ans;
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
a[i][j]=0;
}
}
for (int i=1;i<n;i++){
cin>>x>>y;
a[x][y]=1;
}
// Display
/*
cout<<"Display"<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
*/
int imp=n;
while(adj(a,n)){
bool flag1=1;
int r,c=0;
for(int i=1;i<=imp;i++){
for(int j=1;j<=imp;j++){
if(a[j][i]==1){
flag1=0;
break;
}
}
if(flag1){
c=i;
break;
}
else{
flag1=1;
}
}
if(c!=imp){
for(int i=1;i<=n;i++){
swap(a[i][imp],a[i][c]);
}
ans.push_back(make_pair(2,make_pair(c,imp)));
}
int c1;
for(int i=1;i<=imp;i++){
for(int j=1;j<=imp;j++){
if(a[i][j]){
r=i;
c1=j;
break;
}
}
if(a[r][c1])
break;
}
if(r!=imp){
for(int i=1;i<=n;i++){
swap(a[imp][i],a[r][i]);
}
ans.push_back(make_pair(1,make_pair(r,imp)));
}
imp--;
}
cout<<ans.size()<<endl;
for(int i=0;i<ans.size();i++){
cout<<ans[i].first<<" "<<ans[i].second.first<<" "<<ans[i].second.second<<endl;
}
return 0;
}
/*
check for corner cases(n == 1?)
see the constraint
read the highlighted text again
*/
Ly9NRUhOQVQKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgdHIoYywgaXQpIFwKZm9yKGF1dG8gaXQgPSBjLmJlZ2luKCk7IGl0ICE9IGMuZW5kKCk7IGl0KyspCiNkZWZpbmUgbGwgbG9uZyBsb25nCgovL2NvbnN0IGludCBNQVg9MWUzICsgNTsKaW50IGFbMTAwMF1bMTAwMF07Cgpib29sIGZsYWc9MDsKCmJvb2wgYWRqKGludCBhW11bMTAwMF0saW50IG4pewogICAgZm9yKGludCBpPTE7aTw9bjtpKyspewogICAgICAgIGZvcihpbnQgaj1pO2o8PW47aisrKXsKICAgICAgICAgICAgaWYoYVtpXVtqXT09MSkKICAgICAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBmYWxzZTsKCn0KCmludCBtYWluKCl7CiAgICBpbnQgbix4LHk7CgogICAgdmVjdG9yPHBhaXIgPGludCxwYWlyIDxpbnQsaW50PiA+ID4gYW5zOwoKICAgIGNpbj4+bjsKCiAgICBmb3IoaW50IGk9MTtpPD1uO2krKyl7CiAgICAgICAgZm9yKGludCBqPTE7ajw9bjtqKyspewogICAgICAgICAgICBhW2ldW2pdPTA7CiAgICAgICAgfQogICAgfQoKICAgIGZvciAoaW50IGk9MTtpPG47aSsrKXsKICAgICAgICBjaW4+Png+Pnk7CiAgICAgICAgYVt4XVt5XT0xOwogICAgfQoKLy8gICAgICAgIERpc3BsYXkKICAgIC8qCiAgICBjb3V0PDwiRGlzcGxheSI8PGVuZGw7CiAgICBmb3IoaW50IGk9MTtpPD1uO2krKyl7CiAgICAgICAgZm9yKGludCBqPTE7ajw9bjtqKyspewogICAgICAgICAgICBjb3V0PDxhW2ldW2pdPDwiICI7CiAgICAgICAgfQogICAgICAgIGNvdXQ8PGVuZGw7CiAgICB9CiAgICAqLwoKICAgaW50IGltcD1uOwoKICAgd2hpbGUoYWRqKGEsbikpewogICAgICAgYm9vbCBmbGFnMT0xOwogICAgICAgaW50IHIsYz0wOwoKICAgICAgIGZvcihpbnQgaT0xO2k8PWltcDtpKyspewogICAgICAgICAgICBmb3IoaW50IGo9MTtqPD1pbXA7aisrKXsKICAgICAgICAgICAgICAgIGlmKGFbal1baV09PTEpewogICAgICAgICAgICAgICAgICAgIGZsYWcxPTA7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoZmxhZzEpewogICAgICAgICAgICAgICAgYz1pOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgIGZsYWcxPTE7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYoYyE9aW1wKXsKICAgICAgICAgICAgZm9yKGludCBpPTE7aTw9bjtpKyspewogICAgICAgICAgICAgICAgc3dhcChhW2ldW2ltcF0sYVtpXVtjXSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYW5zLnB1c2hfYmFjayhtYWtlX3BhaXIoMixtYWtlX3BhaXIoYyxpbXApKSk7CiAgICAgICAgfQoKCiAgICAgICAgaW50IGMxOwogICAgICAgIGZvcihpbnQgaT0xO2k8PWltcDtpKyspewogICAgICAgICAgICBmb3IoaW50IGo9MTtqPD1pbXA7aisrKXsKICAgICAgICAgICAgICAgIGlmKGFbaV1bal0pewogICAgICAgICAgICAgICAgICAgIHI9aTsKICAgICAgICAgICAgICAgICAgICBjMT1qOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKGFbcl1bYzFdKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIGlmKHIhPWltcCl7CiAgICAgICAgICAgIGZvcihpbnQgaT0xO2k8PW47aSsrKXsKICAgICAgICAgICAgICAgIHN3YXAoYVtpbXBdW2ldLGFbcl1baV0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGFucy5wdXNoX2JhY2sobWFrZV9wYWlyKDEsbWFrZV9wYWlyKHIsaW1wKSkpOwogICAgICAgIH0KICAgICAgICBpbXAtLTsKICAgIH0KCgoKICAgIGNvdXQ8PGFucy5zaXplKCk8PGVuZGw7CgogICAgZm9yKGludCBpPTA7aTxhbnMuc2l6ZSgpO2krKyl7CiAgICAgICAgY291dDw8YW5zW2ldLmZpcnN0PDwiICI8PGFuc1tpXS5zZWNvbmQuZmlyc3Q8PCIgIjw8YW5zW2ldLnNlY29uZC5zZWNvbmQ8PGVuZGw7CiAgICB9CgogICAgcmV0dXJuIDA7Cgp9CgovKgpjaGVjayBmb3IgY29ybmVyIGNhc2VzKG4gPT0gMT8pCnNlZSB0aGUgY29uc3RyYWludApyZWFkIHRoZSBoaWdobGlnaHRlZCB0ZXh0IGFnYWluCiov