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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Solution {
    List<Integer>[] g;
    int[] used;
    List<String> bad;

    void dfs(int v, int p){
        used[v] = 1;
        for(int i : g[v]){
            if(used[i] == 0){
                dfs(i, v);
            }else if(used[i] == 1 && i != p){
                bad.add((v + 1) + " " + (i + 1));
            }
        }
        used[v] = 2;
    }

    void solve() {
        int n = readInt();
        g = new List[n];
        for(int i = 0;i<n;i++){
            g[i] = new ArrayList<>();
        }

        for(int i = 0;i<n - 1;i++){
            int from = readInt() - 1;
            int to = readInt() - 1;
            g[from].add(to);
            g[to].add(from);
        }

        used = new int[n];
        bad = new ArrayList<>();

        List<Integer> comps = new ArrayList<>();
        for(int i = 0;i<n;i++){
            if(used[i] == 0){
                dfs(i, -1);
                comps.add(i + 1);
            }
        }
        List<String> ans = new ArrayList<>();
        while(comps.size() > 1){
            String a = bad.get(bad.size() - 1);
            bad.remove(bad.size() - 1);
            String q = comps.get(comps.size() - 2) + " " + comps.get(comps.size() - 1);
            comps.remove(comps.size() - 1);
            ans.add(a + " " + q);
        }
        out.println(ans.size());
        for(String i : ans){
            out.println(i);
        }
    }

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

    private void run() {
        try {
            init();
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    private BufferedReader in;
    private StringTokenizer tok = new StringTokenizer("");

    private PrintWriter out;

    private void init() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

//        try {
//            in = new BufferedReader(new FileReader("absum.in"));
//            out = new PrintWriter(new File("absum.out"));
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
    }

    private String readLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private String readString() {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (nextLine == null) return null;
            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken();
    }

    private int readInt() {
        return Integer.parseInt(readString());
    }

    private long readLong() {
        return Long.parseLong(readString());
    }
}