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 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Roads_not_only_in_Berland {

    class link {
        public int linkNum, count;

        public link(int lNum, int cnt) {
            this.linkNum = lNum;
            this.count = cnt;
        }

        @Override
        public String toString() {
            return linkNum / n + " " + linkNum % n + " " + count;
        }

    }

    public int[] colour;
    public int[] dfsNum;
    public int num;

    public void clearBridges() {
        // find all bridges
        findAllBridges();

        // clear bridges from links list
        for (ArrayList<link> ll : links) {
            if (ll == null)
                continue;
            for (int i = 0; i < ll.size(); i++) {
                link tmp = ll.get(i);
                Integer val=bridges.get(tmp.linkNum);
                if (val!=null && val==1) {
                    tmp.count--;
                    if (tmp.count == 0) {
                        ll.remove(i);
                        i--;
                    }
                    bridges.put(tmp.linkNum, 0);
                }
            }
        }

    }

    public void findAllBridges() {

        colour = new int[n];
        dfsNum = new int[n];
        num = 0;
        Arrays.fill(colour, 0);
        for (int i = 0; i < links.size(); i++) {
            if (links.get(i) != null && links.get(i).size() > 0) {
                int start = links.get(i).get(0).linkNum / n;
                dfs(start, -1, n);
            }
        }

    }

    int dfs(int u, int p, int n) {
        colour[u] = 1;
        dfsNum[u] = num++;
        int lastAncestor = num;
        for (int v = 0; v < n; v++) {
            if (graph[u][v] > 0 && v != p) {
                if (colour[v] == 0) {
                    int rec = dfs(v, u, n);
                    if (rec > dfsNum[u]) {
                        // System.out.println("Bridge found: " + u + " " + v);
                        if (!bridges.containsKey(convert(u, v))) {
                            bridges.put(convert(u, v), 1);
                        }
                    }
                    lastAncestor = Math.min(lastAncestor, rec);
                } else {
                    lastAncestor = Math.min(lastAncestor, dfsNum[v]);
                }
            }
        }
        colour[u] = 2;
        return lastAncestor;

    }

    public int convert(int i, int j) {
        int res = Math.min(i, j) * n + Math.max(i, j);
        return res;
    }

    public int convertRev(int i, int j) {
        int res = Math.max(i, j) * n + Math.min(i, j);
        return res;
    }
    void fillTree(int start, int numTree, ArrayList<link> ll) {
        visited[start] = true;
        for (int i = 0; i < n; i++) {
            if (graph[start][i] > 0 && !visited[i]) {
                int con = convert(start, i);
                ll.add(new link(con, graph[start][i]));
                passedLinks.put(con, 1);
                tree[i] = numTree;
                fillTree(i, numTree, ll);
            } else if (graph[start][i] > 0 && visited[i]
                    && !passedLinks.containsKey(convert(start, i))) {
                int con = convert(start, i);
                ll.add(new link(con, graph[start][i]));
                passedLinks.put(con, 1);
                tree[i] = numTree;
            }
        }
    }

    public void bfs() {
        numTrees = 0;
        visited = new boolean[n];

        while (true) {
            int start;
            for (start = 0; start < n; start++) {
                if (tree[start] == -1)
                    break;
            }
            if (start == n)
                break;
            tree[start] = numTrees;
            treeRoots[numTrees] = start;
            visited[start] = true;
            ArrayList<link> linksI = new ArrayList<link>();
            fillTree(start, numTrees, linksI);
            links.add(linksI);
            numTrees++;
        }

    }

    public int n;
    public int[] tree;
    public int[] treeRoots;
    public boolean[] visited;
    public int[][] graph;
    public int numTrees;
    public ArrayList<ArrayList<link>> links = new ArrayList<ArrayList<link>>();
    HashMap<Integer, Integer> passedLinks = new HashMap<Integer, Integer>();
    HashMap<Integer, Integer> bridges = new HashMap<Integer, Integer>();

    public void solve() {

        Scanner read = new Scanner(System.in);
        n = read.nextInt();
        graph = new int[n][n];
        tree = new int[n];
        treeRoots = new int[n];

        Arrays.fill(tree, -1);

        for (int i = 0; i < n - 1; i++) {
            int s1 = read.nextInt() - 1;
            int s2 = read.nextInt() - 1;
            graph[s1][s2]++;
            graph[s2][s1]++;
        }
        // find all links and trees
        bfs();
        if (numTrees == 1) {
            System.out.println(0);
            return;
        }
        // System.out.println(Arrays.toString(tree));
        // System.out.println(links.size());
        // for (ArrayList<link> ll : links) {
        // System.out.println(Arrays.toString(ll.toArray()));
        // }
        clearBridges();

        // System.out.println("cleared");
        // for (ArrayList<link> ll : links) {
        // System.out.println(Arrays.toString(ll.toArray()));
        // }
        ArrayList<String> result = new ArrayList<String>();

        boolean exit = false;
        int count = 0;
        while (!exit) {
            for (int i = 0; i < links.size(); i++) {
                if (links.get(i) != null && links.get(i).size() > 0) {
                    for (int j = 0; j < links.size(); j++) {
                        if (j != i && links.get(j) != null) {
                            link lnk = links.get(i).get(0);
                            if (lnk.count == 1) {
                                lnk.count--;
                                links.get(i).remove(0);
                            } else {
                                lnk.count--;
                            }

                            //System.out.println(lnk.count);
                            result.add((lnk.linkNum / n + 1) + " "
                                    + (lnk.linkNum % n + 1) + " "
                                    + (treeRoots[i] + 1) + " "
                                    + (treeRoots[j] + 1));
                            graph[lnk.linkNum / n][lnk.linkNum % n]--;
                            graph[lnk.linkNum % n][lnk.linkNum / n]--;
                            graph[treeRoots[i]][treeRoots[j]]++;
                            graph[treeRoots[j]][treeRoots[i]]++;
                            int min = Math.min(i, j);
                            int max = Math.max(i, j);
                            links.get(min).addAll(links.get(max));
                            links.set(max, null);
                            count++;
                            clearBridges();
                            break;
                        }
                    }
                }
                // System.out.println(count + " " + numTrees);
                if (count == numTrees - 1) {
                    exit = true;
                    break;
                }
            }
        }

        System.out.println(count);
        for (int i = 0; i < count; i++) {
            System.out.println(result.get(i));
        }
    }

    public static void main(String[] args) {
        new Roads_not_only_in_Berland().solve();

    }

}
