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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	 	PrintWriter pw = new PrintWriter(System.out);
	 	int n = Integer.parseInt(br.readLine());
	 	int[] mark = new int[n-1];
	 	int[] a = new int[n-1];
	 	int[] b = new int[n-1];
	 	DisjointUnionSets dus = new DisjointUnionSets(n);
	 	for(int i=0;i<n-1;i++){
	 		StringTokenizer st = new StringTokenizer(br.readLine());
	 		a[i] = Integer.parseInt(st.nextToken());
	 		b[i] = Integer.parseInt(st.nextToken());
	 		if(dus.find(a[i]-1)!=dus.find(b[i]-1)){
	 			dus.union(a[i]-1, b[i]-1);
	 		}
	 		
	 		else{
	 			mark[i]=1;
	 		}
	 	}
	 	
	 	int[] freq = new int[n];
	 	for(int i=0;i<n;i++){
	 		freq[dus.find(i)]++;
	 	}
	 	int count=0;
	 	
	 	int max = Integer.MIN_VALUE;
	 	for(int i=0;i<n;i++){
	 		if(freq[i]>0){
	 			count++;
	 		}
	 		max = Math.max(max, freq[i]);
	 	}
	 	
	 	pw.println(count-1);
	 	int[] a1 = new int[count-1];
	 	int[] b1 = new int[count-1];
	 	
	 	int store=0;
	 	for(int i=0;i<n;i++){
	 		if(max == freq[i]){
	 			store = i;
	 			break;
	 		}
	 	}
	 	
	 	int co=0;
	 	for(int i=0;i<n;i++){
	 		if(i!=store){
	 			if(freq[i]>0){
	 				a1[co] = store+1;
	 				b1[co] = i+1;
	 				co++;
	 				
	 				if(co == count-1)
	 					break;
	 				
	 			}
	 		}
	 	}
	 	co=0;
	 	for(int i=0;i<n-1;i++){
	 		if(mark[i]==1){
	 			pw.println(a[i]+" "+b[i]+" "+a1[co]+" "+b1[co]);
	 			co++;
	 			if(co==count-1)
	 				break;
	 		}
	 	}
	 	
	 	pw.close();
	 	
	}
}


class DisjointUnionSets extends Main {

	int[] rank, parent;
	int n;
	
	public DisjointUnionSets(int n) {
		rank = new int[n];
		parent = new int[n];
		this.n=n;
		makeSet();
	}
	
	void makeSet() {
		
		for(int i=0;i<n;i++){  // Initially, all elements are in their own set.
			parent[i] = i;
		}
	}
	
	int find(int x){ // Finds the representative of the set that x is an element of
		if(parent[x]!=x){ 
			//if x is not the parent of itself 
	        // Then x is not the representative of his set,
	        
			return find(parent[x]);
			// so we recursively call Find on its parent
			// and move i's node directly under the representative of this set
		}
		else{
			return x;
		}
			
		//return parent[x];
	}
	
	void union(int x, int y){ // Unites the set that includes x and the set that includes y
		int xRoot = find(x); // Find the representatives (or the root nodes) for the set that includes x
		int yRoot = find(y); // And do the same for the set that includes y
		if(xRoot == yRoot)  // Elements are in the same set, no need to unite anything.
			return;
		if(rank[xRoot]<rank[yRoot]){ // If x's rank is less than y's rank
			parent[xRoot] = yRoot; // Then move x under y  so that depth of tree remains less
		}
		
		else if(rank[yRoot]<rank[xRoot]){ // Else if y's rank is less than x's rank
			parent[yRoot] = xRoot; // Then move y under x so that depth of tree remains less
		}
		
		else{ // Else if their ranks are the same
			parent[yRoot] = xRoot; // Then move y under x (doesn't matter which one goes where)
			rank[xRoot] = rank[xRoot] + 1;  // And increment the the result tree's rank by 1
		}
	}

}