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.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;

/**
 * @author timat
 *
 */
public class Task_codeforces {

	public static void main(String[] args) throws IOException {
		FastIO.init();

		int n = FastIO.readInt();

		DSU dsu = new DSU(n);

		LinkedList<int[]> notused = new LinkedList<int[]>();

		for (int i = 0; i < n - 1; i++) {
			int a = FastIO.readInt() - 1;
			int b = FastIO.readInt() - 1;

			if (dsu.findSet(a) == dsu.findSet(b)) {
				notused.addFirst(new int[] { a, b });
			} else {
				dsu.unionSets(a, b);
			}
		}

		int t = 0;
		StringBuilder result = new StringBuilder();
		for (int i = 0; i < n; i++) {
			if (dsu.findSet(0) != dsu.findSet(i)) {
				t++;
				int[] toclose = notused.removeFirst();
				result.append(toclose[0] + 1).append(" ").append(toclose[1] + 1).append(" 1 ").append(i + 1)
						.append("\n");
				dsu.unionSets(0, i);
			}
		}
		System.out.println(t);
		System.out.println(result.toString());

		FastIO.cleanup();
	}

	private static class FastIO {
		private static StringTokenizer tokenizer;
		private static BufferedReader in;

		public static void init() {
			in = new BufferedReader(new InputStreamReader(System.in));
		}

		public static void initf() throws FileNotFoundException {
			initf("in.txt");
		}

		public static void initf(String name) throws FileNotFoundException {
			File file = new File(name);
			in = new BufferedReader(file.exists() ? new FileReader(file) : new InputStreamReader(System.in));
		}

		public static void cleanup() throws IOException {
			in.close();
		}

		public static String readToken() throws IOException {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				tokenizer = new StringTokenizer(in.readLine());
			}
			return tokenizer.nextToken();
		}

		public static int readInt() throws NumberFormatException, IOException {
			return Integer.parseInt(readToken());
		}

	}

	private static class DSU {

		// Tree
		private final ArrayList<Union> unions = new ArrayList<Union>();

		public DSU(int startcap) {
			unions.ensureCapacity(startcap);
			for (int i = 0; i < startcap; i++) {
				makeSet();
			}
		}

		public DSU() {
		}

		/**
		 * Creates new set and returns its index.
		 * 
		 * @return : Index of the new element.
		 */
		public int makeSet() {
			int index = unions.size();
			Union entry = new Union(index);
			unions.add(index, entry);
			return index;
		}

		/**
		 * This method find set in which given set is in.
		 * 
		 * @param setIndex
		 * @return
		 */
		public int findSet(int setIndex) {
			if (unions.get(setIndex).parent == setIndex) {
				return setIndex;
			} else {
				int parent = unions.get(setIndex).parent;
				int result = findSet(parent);
				unions.get(setIndex).parent = result;
				return result;
			}
		}

		/**
		 * This method unites two sets.
		 * 
		 * @param element1
		 *            : Index of the set 1.
		 * @param element2
		 *            : Index if the set 2.
		 */
		public void unionSets(int element1, int element2) {
			int set1 = findSet(element1);
			int set2 = findSet(element2);
			Union es1 = unions.get(set1);
			Union es2 = unions.get(set2);
			if (es1.rank == es2.rank) {
				es1.rank++;
				es2.parent = set1;
				return;
			}
			if (es1.rank > es2.rank) {
				es2.parent = set1;
			} else {
				es1.parent = set2;
			}
		}

		@Override
		public String toString() {
			TreeMap<Integer, StringBuilder> str = new TreeMap<Integer, StringBuilder>();

			for (int unionIndex = 0; unionIndex < unions.size(); unionIndex++) {
				int set = findSet(unionIndex);
				if (!str.containsKey(set)) {
					str.put(set, new StringBuilder());
				}

				StringBuilder b = str.get(set);
				if (b.length() > 0) {
					b.append(", ");
				} else {
					b.append("Set leader : ").append(set).append(" : [");
				}
				b.append(unionIndex);
			}

			StringBuilder result = new StringBuilder();
			Set<Entry<Integer, StringBuilder>> es = str.entrySet();
			for (Entry<Integer, StringBuilder> e : es) {
				result.append(e.getValue().append("]\n"));
			}

			return result.toString();
		}

		private class Union {
			private int parent;
			private int rank = 0;

			private Union(int parent) {
				super();
				this.parent = parent;
			}
		}

	}

}
