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

/**
 * Created by first on 8/12/2018.
 */
public class RoadsNotOnlyInBerland_D {
    public static void main(String  [] args) throws IOException {
        RoadsNotOnlyInBerland_D x = new RoadsNotOnlyInBerland_D();
        x.solve();
    }
    public void solve() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int numOfCities = Integer.parseInt(br.readLine());
        ArrayList<Edge> addedRoads = new ArrayList<>();
        ArrayList<Edge> removedRoads = new ArrayList<>();

        Node [] cities = new Node[numOfCities];

        for(int i = 0; i < numOfCities; i++){
            cities[i] = new Node(i);
        }
        for(int i = 0; i < numOfCities - 1; i++){
            String [] inputs = br.readLine().split(" ");
            int from = Integer.parseInt(inputs[0]) - 1;
            int to = Integer.parseInt(inputs[1]) - 1;
            if(find(cities[from]) != find(cities[to])){
                union(cities[from],cities[to]);
            }else {
                removedRoads.add(new Edge(from, to));
            }
        }

        for(int i = 0; i < numOfCities - 1; i++){
            Node p1 = find(cities[i]);
            Node p2 = find(cities[i+1]);
            if(p1 != p2){
                addedRoads.add(new Edge(p1.index,p2.index));
                union(p1,p2);
            }
        }
        System.out.println(removedRoads.size());
        for(int i = 0; i < removedRoads.size(); i++){
            Edge e1 = removedRoads.get(i);
            Edge e2 = addedRoads.get(i);
            System.out.println((e1.from+1) + " " + (e1.to+1) + " " + (e2.from+1) + " " + (e2.to+1));
        }
    }

    private Node union(Node n1, Node n2){
        Node p1 = find(n1);
        Node p2 = find(n2);
        if(p1.rank < p2.rank){
            p1.parent = p2;
            return p2;
        } else {
            p2.parent = p1;
            if(p1.rank == p2.rank){
                p1.rank++;
            }
            return p1;
        }
    }
    private Node find(Node node){
        if(node.parent != node){
            node.parent = find(node.parent);
        }
        return node.parent;
    }

    private class Node{
        int rank = 0;
        int index;
        Node parent = this;
        public Node(int index){
            this.index = index;
        }
    }
    private class Edge{
        int from,to;
        public Edge(int from, int to){
            this.from = from;
            this.to = to;
        }
    }
}