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.*;

public class RnB {
	
	static int[] union;
	public static int find( int x ) {
		return union[x] == x ? x : ( union[x] = find( union[x] ) );
	}
	
	public static void main( String[] args ) throws IOException {
		BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
		PrintWriter pw = new PrintWriter( new BufferedWriter( new OutputStreamWriter( System.out ) ) );
		
		int N = Integer.parseInt( br.readLine() );
		
		ArrayList<Integer>[] map = new ArrayList[N];
		for(int i = 0; N > i; i++) {
			map[i] = new ArrayList<Integer>();
		}
		
		for(int i = 0; N - 1 > i; i++) {
			String[] line = br.readLine().split(" ");
			int l = Integer.parseInt(line[0]) - 1;
			int r = Integer.parseInt(line[1]) - 1;
			
			map[l].add(r);
			map[r].add(l);
		}
		
		union = new int[N];
		for(int i = 0; N > i; i++) {
			union[i] = i;
		}
		
		LinkedList<Integer> starters = new LinkedList<Integer>();
		ArrayList<Integer> l = new ArrayList<Integer>();
		ArrayList<Integer> r = new ArrayList<Integer>();
		HashSet<String> set = new HashSet<String>();
		
		for(int i = 0; N > i; i++) {
			if( find(i) != i ) {
				continue;
			} //System.out.println( "STARTING WITH " + (i+1) );
			
			starters.push( i );
			
			LinkedList<S> stack = new LinkedList<S>();
			for(int j = 0; map[i].size() > j; j++) {
				stack.push( new S( map[i].get(j), i ) );
			}
			
			while( stack.size() > 0 ) {
				S s = stack.pop();
				
				int curr = find( s.index );
				int prev = find( s.prev );
				
				if( curr != prev ) {
					union[curr] = prev;
				} else {
					//System.out.println( "CYCLE WITH " + (s.index+1) + " & " + (s.prev+1) );
					String ss = Math.max( s.index, s.prev ) + " " + Math.min( s.index, s.prev );
					if( !set.contains( ss ) ) {
						l.add( s.index );
						r.add( s.prev );
						set.add( ss );
					}
					continue;
				}
				
				for(int j = 0; map[s.index].size() > j; j++) {
					int next = map[s.index].get(j);
					if( next == s.prev ) {
						continue;
					}
					
					stack.push( new S( next, s.index ) );
				}
			}
		} //System.out.println( Arrays.toString( union ) );
		
		pw.println( l.size() );
		
		/*while( starters.size() > 0 ) { System.out.print( starters.pop() + " " ); }
		System.out.println();
		System.out.println( l );
		System.out.println( r );*/
		
		for(int i = 0; l.size() > i; i++) {
			while( true ) {
				int x = starters.pop();
				if( find( x ) != find( l.get(i) ) ) {
					pw.print( l.get(i) + 1 );
					pw.print( " " );
					pw.print( r.get(i) + 1 );
					pw.print( " " );
					pw.print( l.get(i) + 1 );
					pw.print( " " );
					pw.println( x + 1 );
					
					union[find(x)] = find( l.get(i) );
					break;
				} else {
					starters.offer( x );
				}
			}
		}
		
		pw.close();
	}
}

class S {
	public int index, prev;
	public S( int index, int prev ) {
		this.index = index;
		this.prev = prev;
	}
}