#include <bits/stdc++.h>
using namespace std;
int n;
vector <int> e[1001];
bool have[1001];
struct node
{
int leftMark, rightMark;
node* sonLeft, *sonRight;
void updateMark()
{
leftMark = sonLeft->leftMark;
rightMark = sonRight->rightMark;
}
}*start, *want;
struct step
{
int fromA, fromB;
int toA, toB;
};
node* addNode(int L, int R, int from)
{
node *t = new node();
t->leftMark = L;
t->rightMark = R;
if(L == R+1)
{
return t;
}
for(int i = 0; i < e[L].size(); i++)
if(e[L][i] != from)
have[e[L][i]] = true;
int M = -1;
for(int j = 0; j < e[R].size(); j++)
if(e[R][j] != from)
if(have[e[R][j]])
M = e[R][j];
for(int i = 0; i < e[L].size(); i++)
have[e[L][i]] = false;
t->sonLeft = addNode(L, M, R);
t->sonRight = addNode(M, R, L);
return t;
}
node* input()
{
for(int i = 1; i <= n; i++)
e[i].clear();
for(int i = 1; i <= n-3; i++)
{
int a, b;
cin >> a >> b;
e[a].push_back(b);
e[b].push_back(a);
}
for(int i = 1; i <= n; i++)
{
int j = i+1;
if(i == n) j = 1;
e[i].push_back(j);
e[j].push_back(i);
}
return addNode(n, 1, -1);
}
void print(node *p, string append)
{
cout << append << p->leftMark << " " << p->rightMark << endl;
if(p->sonLeft != NULL)
print(p->sonLeft, append + "\t");
if(p->sonRight != NULL)
print(p->sonRight, append + "\t");
}
vector <step> record;
void rotateToRight(node *r)
{
step t;
node *s = r->sonLeft;
node *a = s->sonLeft;
node *b = s->sonRight;
node *c = r->sonRight;
t.fromA = s->leftMark;
t.fromB = s->rightMark;
r->sonLeft = a;
r->sonRight = s;
s->sonLeft = b;
s->sonRight = c;
s->updateMark();
r->updateMark();
t.toA = s->leftMark;
t.toB = s->rightMark;
record.push_back(t);
}
void rotateToLeft(node *r)
{
step t;
node *s = r->sonRight;
node *a = r->sonLeft;
node *b = s->sonLeft;
node *c = s->sonRight;
t.fromA = s->leftMark;
t.fromB = s->rightMark;
r->sonLeft = s;
r->sonRight = c;
s->sonLeft = a;
s->sonRight = b;
s->updateMark();
r->updateMark();
t.toA = s->leftMark;
t.toB = s->rightMark;
record.push_back(t);
}
void rotateMiddleToRoot(node *p, int middle)
{
int myMiddle = p->sonLeft->rightMark;
if(myMiddle == middle)
return;
if(myMiddle < middle)
{
rotateMiddleToRoot(p->sonLeft, middle);
rotateToRight(p);
}
else if(myMiddle > middle)
{
rotateMiddleToRoot(p->sonRight, middle);
rotateToLeft(p);
}
}
void normalize(node *p)
{
if(p->leftMark - p->rightMark <= 2) return;
int middle = (p->leftMark + p->rightMark) / 2;
rotateMiddleToRoot(p, middle);
normalize(p->sonLeft);
normalize(p->sonRight);
}
int MAIN()
{
memset(have, 0, sizeof(have));
cin >> n;
start = input();
normalize(start);
vector <step> record1 = record;
record.clear();
want = input();
normalize(want);
cout << record.size() + record1.size() << endl;
for(int i = 0; i < record1.size(); i++)
cout << record1[i].fromA << " " << record1[i].fromB << endl;
for(int i = record.size()-1; i >= 0; i--)
cout << record[i].toA << " " << record[i].toB << endl;
return 0;
}
int main()
{
#ifdef LOCAL_TEST
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios :: sync_with_stdio(false);
cout << fixed << setprecision(16);
return MAIN();
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbjsKdmVjdG9yIDxpbnQ+IGVbMTAwMV07CmJvb2wgaGF2ZVsxMDAxXTsKCnN0cnVjdCBub2RlCnsKCWludCBsZWZ0TWFyaywgcmlnaHRNYXJrOwoJbm9kZSogc29uTGVmdCwgKnNvblJpZ2h0OwoJdm9pZCB1cGRhdGVNYXJrKCkKCXsKCQlsZWZ0TWFyayA9IHNvbkxlZnQtPmxlZnRNYXJrOwoJCXJpZ2h0TWFyayA9IHNvblJpZ2h0LT5yaWdodE1hcms7Cgl9Cn0qc3RhcnQsICp3YW50OwoKc3RydWN0IHN0ZXAKewoJaW50IGZyb21BLCBmcm9tQjsKCWludCB0b0EsIHRvQjsKfTsKCm5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