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.Iterator;
import java.util.Queue;
import java.util.Scanner;
import java.util.Vector;
import java.util.concurrent.ArrayBlockingQueue;


public class _25D {
	
	static Scanner scanner = new Scanner(System.in);
	static int N, ncom;
	static Vector<Integer>[] vects;
	static int[] com, visit;
	static int[][] mat;
	static Queue<Integer> qu = new ArrayBlockingQueue<Integer>(2000);

	public static void main(String[] args) {
		N = scanner.nextInt();
		vects = new Vector[N+1];
		mat = new int[N+1][N+1];
		for (int i=1;i<=N;++i) {
			vects[i] = new Vector<Integer>();
		}
		for (int i=1;i<=N-1;++i) {
			int fr, to;
			fr = scanner.nextInt();
			to = scanner.nextInt();
			vects[fr].add(to);
			vects[to].add(fr);
			mat[fr][to] = mat[fr][to] = 1;
		}
		com = new int[2000];
		visit = new int[N+1];
		ncom = 0;
		for (int i=1;i<=N;++i) {
			if (visit[i] == 0) {
				ncom++;
				visit[i] = ncom;
				com[ncom] = i;
				dfs(i,0);
			}
		}

		if (ncom == 1) {
			System.out.println(0);
		}
		else {
			System.out.println(ncom-1);
			for (int i=2;i<=ncom;++i) {
				System.out.println(qu.poll() + " " + qu.poll() + " " + com[1] + " " + com[i]);
			}
		}
	}

	private static void dfs(int i, int parent) {
		Iterator<Integer> it = vects[i].iterator();
		while (it.hasNext()) {
			int next = it.next();
			if (next == parent) {
				continue;
			}
			if (visit[next] == 0) {
				visit[next] = ncom;
				dfs(next, i);
			}
			else {
				if (mat[i][next] == 1) {
					qu.add(i);
					qu.add(next);
					mat[i][next] = mat[next][i] = 0;
				}
			}
		}
		
	}

}