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 test {
    int INF = (int)1e9;
    long MOD = 1000000007;
    
    
    int n;
    int[][] g;
    boolean[] vis;
    
    int[] id, sz;
    int[][] o;
    int q;
    
    
    int go(int v, int p, int x) {
        if(vis[v]) return 0;
        vis[v] = true;
//        System.out.println("in go: "+(v+1)+" "+(p+1)+" "+x);
        int rs = 0;
//        System.out.println("for: "+v);
        for(int u=0; u<n; u++) if(g[v][u]>0) {
//            if(u != p) {
                if(!vis[u]) {
                    id[u] = x;
                }
                rs += go(u, v, x) + 1;
//            }
        }
        return rs;
    }
    
    boolean rm(int v, int p) {
        if(vis[v]) return false;
        vis[v] = true;
        for(int u=0; u<n; u++) if(g[v][u]>0) {
            if(u!=p) {
                if(vis[u]) {
                    o[q][0] = v+1;
                    o[q][1] = u+1;
                    g[u][v] = g[v][u] = 0;
                    return true;
                }
                boolean x = rm(u, v);
                if(x) return x;
            }
        }
        return false;
    }
    
    int find(int v) {
        if(id[v] != v)
            id[v] = find(id[v]);
        return id[v];
    }
    
    void union(int v, int u) {
        v = find(v);
        u = find(u);
        vis = new boolean[n];
        if(sz[v]>0) {rm(v, -1); sz[v]--;}
        else {rm(u, -1); sz[u]--;}
        o[q][2] = v+1;
        o[q][3] = u+1;
        q++;
//        System.out.println("new edge: "+(v+1)+" "+(u+1));
        g[u][v] = g[v][u] = 1;
        id[u] = v;
        sz[v] += sz[u];
    }
    
    void solve(InputReader in, PrintWriter out) throws IOException {
        n = in.nextInt();
        g = new int[n][n];
        for(int i=0; i<n-1; i++) {
            int u = in.nextInt()-1;
            int v = in.nextInt()-1;
            g[u][v] = g[v][u] = 1;
        }
        id = new int[n];
        sz = new int[n];
        for(int i=0; i<n; i++) {
            id[i] = i;
            sz[i] = 1;
        }
        q = 0;
        vis = new boolean[n];
        int t = 0;
        for(int i=0; i<n; i++) {
            if(!vis[i]) {
                int rs = go(i, -1, i)/2;
                int l = -t;
                t = 0;
                for(int j=0; j<n; j++) {
                    if(vis[j]) t++;
                }
                l += t;
                id[i] = i;
                sz[i] = rs-l+1;
//                System.out.println("got: "+rs+" "+l);
            }
        }
//        System.out.println(Arrays.toString(id));
//        System.out.println(Arrays.toString(sz));
//        System.out.println("check 1");
        int rs = 0;
        o = new int[n][4];
        q = 0;
        for(int i=0; i<n; i++) {
            for(int j=i+1; j<n; j++) {
                int pi = find(i);
                int pj = find(j);
                if(pi!=pj && (sz[pi]>0 || sz[pj]>0)) {
                    union(i, j);
//                    System.out.println(Arrays.toString(id));
//                    System.out.println(Arrays.toString(sz));
                }
            }
        }
//        System.out.println("check 2");
        out.println(q);
        for(int i=0; i<q; i++) {
            out.println(o[i][0]+" "+o[i][1]+" "+o[i][2]+" "+o[i][3]);
        }
    }
    
    
    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new test().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}