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

public class D implements Runnable{
	public static void main (String[] args) {new Thread(null, new D(), "_cf", 1 << 28).start();}

	int n;
	ArrayList<Edge>[] adj;
	boolean[] cycle, vis;
	
	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");
		
		n = fs.nextInt();
		Edge[] es = new Edge[n-1];
		adj = new ArrayList[n];
		for(int i = 0; i < n; i++)
			adj[i] = new ArrayList<>();
		for(int i = 0; i < n-1; i++) {
			int u = fs.nextInt()-1;
			int v = fs.nextInt()-1;
			Edge e = new Edge(u, v, i);
			es[i] = e;
			adj[u].add(e);
			adj[v].add(e);
		}
		cycle = new boolean[n-1];
		vis = new boolean[n];
		for(int i = 0; i < n; i++) {
			if(vis[i]) continue;
			dfs(i, -1);
		}
		ArrayList<int[]> res = new ArrayList<>();
		DSU ds = new DSU(n);
		for(Edge e : es)
			ds.union(e.v, e.u);
		for(int i = 0; i < cycle.length; i++) if(cycle[i]) {
			int[] add = new int[4];
			Arrays.fill(add, -1);
			add[0] = es[i].u;
			add[1] = es[i].v;
			for(int j = 0; j < n; j++) {
				boolean go = ds.union(j, add[0]);
				if(go) {
					add[2] = add[0];
					add[3] = j;
					break;
				}
			}
			if(add[3] < 0) throw new RuntimeException("???");
			res.add(add);
		}
		out.println(res.size());
		for(int[] a : res) {
			for(int j = 0; j < 4; j++)
				out.printf("%d ", a[j]+1);
			out.println();
		}
		
		out.close();
	}
	
	void dfs(int u, int p) {
		vis[u] = true;
		for(Edge e : adj[u]) {
			int v = e.getAlt(u);
			if(v == p) continue;
			if(vis[v]) {
				cycle[e.id] = true;
			}
			else {
				dfs(v, u);
			}
		}
	}
	
	class DSU {
		int n, par[];
		DSU(int a) {
			n = a;
			par = new int[n];
			for(int i = 0; i < n; i++)
				par[i] = i;
		}
		int find(int u) {
			if(u == par[u]) return u;
			return par[u] = find(par[u]);
		}
		boolean union(int u, int v) {
			int pu = find(u);
			int pv = find(v);
			if(pu == pv) return false;
			par[pv] = pu;
			return true;
		}
	}
	
	class Edge {
		int u, v, id;
		Edge(int a, int b, int i) {
			u = a;
			v = b;
			id = i;
		}
		int getAlt(int a) {
			if(a == u) return v;
			return u;
		}
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}