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 Main implements Runnable {

    int[] parent;
    int n;

    public void solve() throws IOException {
        n = nextInt();
        //int[][] edges = new int[n][n];
        parent = new int[n];
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
        ArrayList<String> removed = new ArrayList<String>();
        ArrayList<String> added = new ArrayList<String>();
        for (int i = 0; i < n - 1; i++) {
            int t = nextInt() - 1;
            int f = nextInt() - 1;
            if (!add(f, t)) {
                t++;
                f++;
                removed.add(t + " " + f);
            }
            //System.out.println(i);
            //print(parent);
        }
        for (int i = 1; i < n; i++) {
            int f = getParent(parent[i - 1]);
            int t = getParent(parent[i]);
            if (t != f) {
                //int f = parent[i - 1] + 1;
                //int t = parent[i] + 1;
                added.add((f + 1) + " " + (t + 1));
                add(f, t);
            }
        }
        System.out.println(added.size());
        for (int i = 0; i < added.size(); i++) {
            System.out.println(removed.get(i) + " " + added.get(i));
        }
    }

    boolean add(int t, int f) {
        int fParent = getParent(f);
        int tParent = getParent(t);
        if (tParent == fParent) {
            return false;
        }
        /*for (int i = 0; i < n; i++) {
         if (parent[i] == fParent) {
         parent[i] = tParent;
         }
         }*/
        parent[fParent] = tParent;
        return true;
    }

    int getParent(int cur) {
        if (parent[cur] == cur) {
            return cur;
        }
        return parent[cur] = getParent(parent[cur]);
    }

    void shuffle(int[] a) {
        int N = a.length;
        for (int i = 0; i < N / 2; i++) {
            int j = (int) (Math.random() * N);
            int t = a[i];
            a[i] = a[j];
            a[j] = t;
        }
    }

    void print(int[] a) {
        System.out.println();
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
    }

    void print(int[][] arr) {
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }

    boolean nextPermutation(int[] arr) {
        int f = -1;
        for (int i = arr.length - 2; i >= 0; i--) {
            if (arr[i + 1] > arr[i]) {
                f = i;
                break;
            }
        }
        if (f == -1) {
            return false;
        }
        int s = -1;
        for (int i = arr.length - 1; i >= 0; i--) {
            if (arr[i] > arr[f]) {
                s = i;
                break;
            }
        }
        int d = arr[f];
        arr[f] = arr[s];
        arr[s] = d;

        f++;
        int l = arr.length - 1;
        while (f < l) {
            d = arr[f];
            arr[f] = arr[l];
            arr[l] = d;
            f++;
            l--;
        }
        return true;
    }

    //-----------------------------------------------------------
    public static void main(String[] args) {
        new Main().run();
    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            tok = null;
            solve();
            in.close();
        } catch (IOException e) {
            System.exit(0);
        }
    }

    public String nextToken() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    BufferedReader in;
    StringTokenizer tok;
}