Problem: Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way roads. Because of the recent financial crisis, the Berland Government is strongly pressed for money, so to build a new road it has to close some of the existing ones. Every day it is possible to close one existing road and immediately build a new one. Your task is to determine how many days would be needed to rebuild roads so that from each city it became possible to reach all the others, and to draw a plan of closure of old roads and building of new ones.

Input

The first line contains integer n (2 ≤ n ≤ 1000) — amount of cities in Berland and neighboring countries. Next n - 1 lines contain the description of roads. Each road is described by two space-separated integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — pair of cities, which the road connects. It can't be more than one road between a pair of cities. No road connects the city with itself.

Output

Output the answer, number t — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output t lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between cities i and j became closed and a new road between cities u and v is built. Cities are numbered from 1. If the answer is not unique, output any.

Examples

Input

2
1 2


Output

0


Input

7
1 2
2 3
3 1
4 5
5 6
6 7


Output

1
3 1 3 7

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
	static Scanner f = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		solve();
		out.close();
	}

	static void solve() {
		int n = f.nextInt();
		ArrayList<Integer>[] arr = new ArrayList[n+1];
		Dsu dsu = new Dsu(n+1);
		for(int i=0;i<=n;i++) {
			arr[i] = new ArrayList<>();
		}

		for(int i=1;i<n;i++) {
			int u = f.nextInt(), v = f.nextInt();
			arr[u].add(v);
			arr[v].add(u);
			dsu.join(u, v);
		}


		//kinek mennyi felesleges éle van?
		TreeMap<Integer, Integer> map = new TreeMap<>();
		int[] cnt = new int[n+1];
		for(int i=1;i<=n;i++) {
			int par = dsu.getPar(i);
			cnt[par]++;
			if(map.containsKey(par)) {
				map.put(par, map.get(par) + arr[i].size());
			} else {
				map.put(par, arr[i].size());
			}
		}

		Queue<TreeSet<Pair>> many = new ArrayDeque<>();
		Queue<Integer> single = new ArrayDeque<>();
		boolean[] bol = new boolean[n+1];
		int ans = 0;
		for(Map.Entry<Integer, Integer> i : map.entrySet()) {
			int edgePlus = (i.getValue() - (cnt[dsu.getPar(i.getKey())] - 1) * 2) / 2;

			if(edgePlus == 0) {
				single.add(i.getKey());
			} else {
				Queue<int[]> qu = new ArrayDeque<>();
				qu.add(new int[] {i.getKey(), -1});
				bol[i.getKey()] = true;
				TreeSet<Pair> set = new TreeSet<>();
				while(!qu.isEmpty()) {
					int[] now = qu.poll();
					for(int j : arr[now[0]]) {
						if(now[1] != j) {
							if(bol[j]){
								set.add(new Pair(Math.min(j, now[0]), Math.max(j, now[0])));
							} else {
								bol[j] = true;
								qu.add(new int[] {j, now[0]});
							}
						}
					}
				}

				many.add(set);
				ans += set.size();
			}

		}

		out.println(ans);
		while(!many.isEmpty()) {
			TreeSet<Pair> now = many.poll();
			int last = 0;
			for(Pair p : now) {
				int next = single.poll();
				last = next;
				out.println(p.x+" "+p.y+" "+p.x+" "+next);
			}

			single.add(last);

		}



	}

	static class Pair implements Comparable<Pair> {
		int x, y;
		Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(Pair o) {
			if(o.x == x && o.y == y) {
				return 0;
			}
			int loc = Integer.compare(x, o.x);
			return loc == 0 ? Integer.compare(y, o.y) : loc;
		}

	}


	static class Dsu {
		int[] par;
		int[] size;

		Dsu(int n) {
			par = new int[n];
			size = new int[n];
			for(int i = 0;i<n;i++) {
				par[i] = i;
				size[i] = 1;
			}
		}

		int getPar(int x) {			//get parent
			if(x == par[x]) {
				return x;
			}
			return par[x] = getPar(par[x]);
		}

		void join(int a, int b) {	//join sets
			a = getPar(a);
			b = getPar(b);

			if(a != b) {
				if(size[a] < size[b]) {
					int c = a;
					a = b;
					b = c;
				}
				par[b] = a;
				size[a] += b;
			}
		}
	}
		


}