from collections import deque N=int(input()) E={v:set() for v in range(1,N+1)} F={} for _ in range(N): a,b=map(int,input().split()) E[a].add(b) E[b].add(a) F[(a,b)]=False T=[False]*(N+1) S=deque([1]) T[1]=True while S: v=S.pop() for u in E[v]: if not T[u]: S.append(u) T[u]=True a,b=min(u,v),max(u,v) F[(a,b)]=True p,q=min(F,key=lambda x:F[x]) E[p].remove(q) E[q].remove(p) T=[0]*(N+1) D=[0]*(N+1) S=deque([p]) T[p]=float("inf") while S: v=S.pop() for u in E[v]: if not T[u]: S.append(u) D[u]=D[v]+1 T[u]=v H=D[q] P=[0]*(H+1) P[0]=q y=q i=0 while y!=p: i+=1 y=T[y] P[i]=y print(H+1) X=[(p,q)]+[(P[i],P[i+1]) for i in range(H)] print("\n".join(map(lambda x:"{} {}".format(x[0],x[1]),X)))