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.io.*;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;


public class Main implements Runnable {
    static final int MOD = (int) 1e9 + 7;
    static final int MI = (int) 1e9;
    static final long ML = (long) 1e18;
    static final Reader in = new Reader();
    static final PrintWriter out = new PrintWriter(System.out);
    StringBuilder answer = new StringBuilder();

    public static void main(String[] args) {
        new Thread(null, new Main(), "persefone", 1 << 28).start();
    }

    @Override
    public void run() {
        solve();
        printf();
        flush();
    }


    void solve() {
        int n = in.nextInt();
        DSU dsu = new DSU(n);
        int[] deg = new int[n];
        List<int[]> redunduncies = new ArrayList<>();
        for (int i = 0; i < n - 1; i++) {
            int from = in.nextInt() - 1;
            int to = in.nextInt() - 1;
            deg[from]++;
            deg[to]++;
            if (dsu.isConnected(from, to)) {
                redunduncies.add(new int[] {from, to});
            } else {
                dsu.unite(from, to);
            }
        }

        List<Integer>[] cc = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            int parent = dsu.find(i);
            if (cc[parent] == null) cc[parent] = new ArrayList<>();
            cc[parent].add(i);
        }


        int count = dsu.countCC;
        if (count == 1) {
            printf(0);
            return;
        }

        printf(count - 1);
        List<int[]>[] mapByParent = new ArrayList[n];
        for (int[] red : redunduncies) {
            int parent = dsu.find(red[0]);
            if (mapByParent[parent] == null) mapByParent[parent] = new ArrayList<>();
            mapByParent[parent].add(red);
        }

        int[] next = new int[n];
        int pos = n;
        for (int i = n - 1; i >= 0; i--) {
            next[i] = pos;
            if (cc[i] != null) pos = i;
        }

        List<String> ans = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (mapByParent[i] != null) {
                int size = mapByParent[i].size(), cur = next[i];
                while (size > 0 && cur < n) {
                    int[] a = mapByParent[i].remove(--size);
                    dsu.unite(a[1], cc[cur].get(0));
                    ans.add((a[0] + 1) + " " + (a[1] + 1) + " " + (a[1] + 1) + " " + (cc[cur].get(0) + 1));
                    cur = next[cur];
                    count--;
                }
            }
        }
        if (count > 0) {
            int[] prev = new int[n];
            pos = -1;
            for (int i = 0; i < n; i++) {
                prev[i] = pos;
                if (cc[i] != null) pos = i;
            }
            for (int i = n - 1; i > -1; i--) {
                if (mapByParent[i] != null) {
                    int size = mapByParent[i].size(), cur = prev[i];
                    while (size > 0 && cur > -1) {
                        int[] a = mapByParent[i].get(size - 1);
                        if (!dsu.isConnected(a[1], cc[cur].get(0))) {
                            ans.add((a[0] + 1) + " " + (a[1] + 1) + " " + (a[1] + 1) + " " + (cc[cur].get(0) + 1));
                            mapByParent[i].remove(--size);
                        }
                        cur = prev[cur];
                    }
                }
            }
        }
        for (String res : ans) printf(res);
    }

    static class DSU {
        private int vertex, countCC;
        private int[] id, size;

        public DSU(int vertex) {
            this.vertex = vertex;
            this.id = IntStream.range(0, vertex).toArray();
            this.size = new int[vertex];
            Arrays.fill(size, 1);
            countCC = vertex;
        }

        int find(int i) {
            while (i != id[i]) i = id[i];
            return i;
        }

        void unite(int i, int j) {
            int x = find(i);
            int y = find(j);
            if (x == y) return;
            countCC--;
            if (size[x] > size[y]) {
                id[y] = id[x];
                size[x] += size[y];
                size[y] = 0;
                return;
            }
            id[x] = id[y];
            size[y] += size[x];
            size[x] = 0;
        }

        boolean isConnected(int i, int j) {
            return find(i) == find(j);
        }

        int connectedComponents() {
            return countCC;
        }
    }


    void printf() {
        out.print(answer);
    }

    void close() {
        out.close();
    }

    void flush() {
        out.flush();
    }

    void printf(Stream<?> str) {
        str.forEach(o -> add(o, " "));
        add("\n");
    }


    void printf(Object... obj) {
        printf(false, obj);
    }

    void printfWithDescription(Object... obj) {
        printf(true, obj);
    }


    private void printf(boolean b, Object... obj) {

        if (obj.length > 1) {
            for (int i = 0; i < obj.length; i++) {
                if (b) add(obj[i].getClass().getSimpleName(), " - ");
                if (obj[i] instanceof Collection<?>) {
                    printf((Collection<?>) obj[i]);
                } else if (obj[i] instanceof int[][]) {
                    printf((int[][]) obj[i]);
                } else if (obj[i] instanceof long[][]) {
                    printf((long[][]) obj[i]);
                } else if (obj[i] instanceof double[][]) {
                    printf((double[][]) obj[i]);
                } else printf(obj[i]);
            }
            return;
        }

        if (b) add(obj[0].getClass().getSimpleName(), " - ");
        printf(obj[0]);
    }

    void printf(Object o) {
        if (o instanceof int[])
            printf(Arrays.stream((int[]) o).boxed());
        else if (o instanceof char[])
            printf(new String((char[]) o));
        else if (o instanceof long[])
            printf(Arrays.stream((long[]) o).boxed());
        else if (o instanceof double[])
            printf(Arrays.stream((double[]) o).boxed());
        else if (o instanceof boolean[]) {
            for (boolean b : (boolean[]) o) add(b, " ");
            add("\n");
        } else
            add(o, "\n");
    }

    void printf(int[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(long[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(double[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(boolean[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(Collection<?> col) {
        printf(col.stream());
    }

    <T, K> void add(T t, K k) {
        if (t instanceof Collection<?>) {
            ((Collection<?>) t).forEach(i -> add(i, " "));
        } else if (t instanceof Object[]) {
            Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
        } else
            add(t);
        add(k);
    }


    <T> void add(T t) {
        answer.append(t);
    }

    @SuppressWarnings("unchecked")
    <T extends Comparable<? super T>> T min(T... t) {
        if (t.length == 0)
            return null;
        T m = t[0];
        for (int i = 1; i < t.length; i++)
            if (t[i].compareTo(m) < 0)
                m = t[i];
        return m;
    }

    @SuppressWarnings("unchecked")
    <T extends Comparable<? super T>> T max(T... t) {
        if (t.length == 0)
            return null;
        T m = t[0];
        for (int i = 1; i < t.length; i++)
            if (t[i].compareTo(m) > 0)
                m = t[i];
        return m;
    }

    static class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>>
            implements Comparable<Pair<K, V>> {
        private K k;
        private V v;

        Pair(K k, V v) {
            this.k = k;
            this.v = v;
        }

        @SuppressWarnings("unchecked")
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || !(o instanceof Pair)) return false;
            Pair<K, V> p = (Pair<K, V>) o;
            return k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0;
        }

        @Override
        public int hashCode() {
            int hash = 31;
            hash = hash * 89 + k.hashCode();
            hash = hash * 89 + v.hashCode();
            return hash;
        }

        @Override
        public int compareTo(Pair<K, V> pair) {
            return k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k);
        }

        @Override
        public Pair<K, V> clone() {
            return new Pair<K, V>(this.k, this.v);
        }

        @Override
        public String toString() {
            return String.valueOf(k).concat(" ").concat(String.valueOf(v)).concat("\n");
        }
    }

    static class Reader {
        private BufferedReader br;
        private StringTokenizer st;

        Reader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }


        String next() {
            try {
                while (st == null || !st.hasMoreTokens()) {
                    st = new StringTokenizer(br.readLine());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextInt();
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
}

