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

public class D25 {
	
	public static void main(String args[]) throws Exception{
		FastReader reader = new FastReader();
		int n = reader.I();
		ArrayList<Integer> graph[] = new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i] = new ArrayList<>();
		}
		for(int i=0;i<n-1;i++) {
			int from = reader.I() - 1;
			int dest = reader.I() - 1;
			graph[from].add(dest);
			graph[dest].add(from);
		}
		
		int nChanges = 0;
		int changes[][] = new int[n][];
		for(int i=0;i<n;i++) {
			changes[i] = new int[4];
		}
		boolean found = false;
		do{
			found = false;
			int visited[] = new int[n];
			// 0 not visited
			// 1 visiting
			// 2 visited
			int color = 2;
			for(int i=0;i<n;i++) {
				if(found) break;
				if(visited[i] == 0) {
					//System.out.println(i);
					SimpleEntry<Integer, Integer> toDelete = visit(i, graph, -1, visited, color++);
					if(toDelete != null) {
						//System.out.println(toDelete);
						found = true;
						for(int k=0;k<n;k++) {
							if(visited[k] != visited[i]) {
								changes[nChanges][0] = toDelete.getKey();
								changes[nChanges][1] = toDelete.getValue();
								changes[nChanges][2] = toDelete.getKey();
								changes[nChanges][3] = k;
								nChanges++;
								graph[toDelete.getKey()].remove(toDelete.getValue());
								graph[toDelete.getValue()].remove(toDelete.getKey());
								graph[toDelete.getKey()].add(k);
								graph[k].add(toDelete.getKey());
								break;
							}
						}
					
					}
				}
			}
		} while(found == true);
		System.out.println(nChanges);
		for(int i=0;i<nChanges;i++) {
			for(int k=0;k<4;k++)
				System.out.print((changes[i][k]+1) + " ");
			System.out.println("");
		}
	}
	
	public static SimpleEntry<Integer, Integer> visit(int now, ArrayList<Integer> graph[], int parent, int visited[], int color) {
		visited[now] = 1;
		SimpleEntry<Integer, Integer> result = null;
		
		for(int i=0;i<graph[now].size();i++) {
			int to = graph[now].get(i);
			if(to == parent) {
				continue;
			}
			if(visited[to] == 1) {
				result = new SimpleEntry<>(now, to);
			}
			if(visited[to] == 0 && result == null) {
				result = visit(to, graph, now, visited, color);
			} else if(visited[to] == 0) {
				visit(to, graph, now, visited, color);
			}
		}
		
		visited[now] = color;
		return result;
	}

	static BufferedReader br;
    static long M = (long) 1e9 + 7;

    static class FastReader {

        StringTokenizer st;

        public FastReader() throws FileNotFoundException {
            //br=new BufferedReader(new FileReader("C:\\Users\\shree\\Downloads\\B-small-practice.in"));
            br = new BufferedReader(new InputStreamReader(System.in));

        }

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

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

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

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

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

        public boolean hasNext() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return false;
                }
                st = new StringTokenizer(s);
            }
            return true;
        }

    }
}