#include <bits/stdc++.h>

#include "testlib.h"

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define fi first
#define se second

const int maxn = 3000006;

pair<int, int> edges[maxn];
int pn[maxn];
int n;

int main(int argc, char* argv[])
{
    registerGen(argc, argv, 1);
	int test = atoi(argv[1]);
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        a--, b--;
		edges[i] = {a, b};
    }
    for (int i = 0; i < n; i++) pn[i] = i;
	//dont shuffle sample
	if (test != 1) {
		shuffle(pn, pn + n);
		shuffle(edges, edges + n - 1);
	}
    printf("%d\n", n);
	for (int i = 0; i < n - 1; i++) printf("%d %d\n", pn[edges[i].first] + 1, pn[edges[i].second] + 1);
    return 0;
}
