4
1 4
3 1
3 4
 5
4 1
4 3
5 3
2 4
 21
7 15
13 1
14 3
4 10
2 3
16 18
17 20
16 20
8 4
3 12
2 17
13 11
16 1
13 2
13 5
8 9
6 14
3 17
16 9
13 8
 3
3 1
3 2
 6
5 2
5 3
1 4
3 1
5 6
 60
17 34
46 22
50 44
46 33
41 21
31 33
48 6
38 19
35 60
2 24
49 29
7 53
34 1
19 55
32 1
31 42
27 28
4 53
6 50
21 34
1 10
12 36
54 8
16 13
51 43
45 51
54 20
13 53
34 33
49 33
51 11
59 34
15 5
59 28
30 39
13 30
58 4
34 14
3 9
19 34
4 18
26 48
56 54
3 43
57 25
3 41
35 3
48 44
19 13
54 1
23 31
59 47
5 1
46 40
6 26
20 25
37 5
17 24
20 52
 3
3 2
1 2
 39
6 13
15 39
10 35
31 28
4 21
12 39
3 7
3 13
6 1
5 14
36 28
12 15
18 38
30 29
19 34
36 16
20 22
8 13
38 32
26 39
21 37
1 7
15 27
12 26
8 3
6 14
29 2
25 23
32 21
5 16
32 25
6 8
13 10
23 30
34 37
29 33
28 14
36 5
 10
5 9
8 5
7 6
7 9
3 9
2 1
7 2
3 6
7 1

1
3 4 1 2  0
 3
13 2 1 7 3 17 1 19 13 8 1 21  0
 0
 2
48 44 1 6 6 26 1 12  0
 7
12 15 1 2 1 7 1 9 12 26 1 11 8 3 1 12 6 8 1 17 28 14 1 20 36 5 1 24  2
3 6 1 4 7 1 1 10 
# Link: http://codeforces.com/contest/25/problem/D

import os
import sys
import math
import itertools
from io import BytesIO, IOBase

#<fast I/O>
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
#</fast I/O>

#<template>
mod=(10**9)+7
pi=3.14159265358979323846264338327950

def i1():   #int(input())
    return int(sys.stdin.readline())

def sf():   #input()
    return sys.stdin.readline()

def mi():   #map(int(input()))
    return map(int,sys.stdin.readline().split())

def arr():  #list(map(int,input().split()))
    return list(map(int,sys.stdin.readline().split()))

def pf(ans): #print(x)
    return sys.stdout.write(str(ans)+"\n")

def gcd(a,b):
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)

def lcm(a,b):
    return (a*b)//gcd(a,b)
#</template>

#<testcases>
#sys.stdin=open('input.txt','r')
#sys.stdout=open('output.txt','w')
#</testcases>



#<solve>
def solve():
    n = int(input())
    parent = [i for i in range(n+1)]
    rank = [0] * (n+1)

    # Keep track of the roads that needs to be removed
    close = []

    # Keep track of the roads that needs to be built
    build = []

    # Find the representative of the set that has vertex as one of it's descendents
    # using path compression
    def find(vertex):
        if vertex != parent[vertex]:
            parent[vertex] = find(parent[vertex])
        return parent[vertex]

    # Using union by rank
    def union(x, y):
        parent_x = find(x)
        parent_y = find(y)
        if rank[parent_x] < rank[parent_y]:
            parent[parent_x] = parent_y
        elif rank[parent_y] < rank[parent_x]:
            parent[parent_y] = parent_x
        else:
            parent[parent_y] = parent_x
            rank[parent_x] += 1

    def roads():
        for i in range(n-1):
            u, v = map(int, input().split())

            # If u and v have same parent or they are in the same set then this road needs 
            # to be removed.
            if find(u) == find(v):
                close.append([u, v])
            else:
                # union u, v
                union(u, v)
        
        for i in range(2, n+1):
            # if i and 1 are not in the same set then union them and built the road 
            # between these nodes
            if find(i) != find(1):
                union(i, 1)
                build.append([1, i])
    roads()
    print(len(build))
    for i in range(len(close)):
        print(close[i][0], close[i][1], build[i][0], build[i][1])
#</solve>

#<solution>
#tc=i1()
#for t in range (tc):
solve()
#<solution>