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.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class RoadsNotOnlyBerland<V> {

    private static int n;

    private static Node<Integer>[] cities;

    private static List<Road> buildeds = new ArrayList<Road>();

    private static List<Road> closeds = new ArrayList<Road>();;

    private static RoadsNotOnlyBerland<Integer> berland = new RoadsNotOnlyBerland<Integer>();

    private static class Node<V> {

	V node;

	Node<V> parent;

	int rank;

	public Node() {
	    this.parent = this;
	}
    }

    public Node<V> makeSet(V x) {

	Node<V> node = new Node<V>();

	node.node = x;
	node.parent = node;
	node.rank = 0;

	return node;
    }

    public void link(Node<V> x, Node<V> y) {

	if (x.rank > y.rank) {
	    y.parent = x;
	} else {
	    x.parent = y;
	    if (x.rank == y.rank) {
		y.rank++;
	    }
	}
    }

    public Node<V> findSet(Node<V> x) {

	if (x.parent != x) {
	    x.parent = findSet(x.parent);
	}

	return x.parent;
    }

    public void union(Node<V> x, Node<V> y) {

	Node<V> rtX = findSet(x);
	Node<V> rtY = findSet(y);
	if (rtX.parent != rtY.parent) {
	    link(rtX, rtY);
	}
    }

    public V getNode(Node<V> x) {
	return x.node;
    }

    private static Node<Integer> get(int key) {

	Node<Integer> node = cities[key];

	if (node == null) {
	    node = berland.makeSet(key);
	    cities[key] = node;
	}

	return node;
    }

    private static boolean connected(Node<Integer> from, Node<Integer> to) {

	boolean valid;

	Node<Integer> key1 = berland.findSet(from);
	Node<Integer> key2 = berland.findSet(to);
	valid = (key1.node == key2.node);

	return valid;
    }

    private static class Road {

	Node<Integer> from;

	Node<Integer> to;

	public Road(Node<Integer> from, Node<Integer> to) {
	    this.from = from;
	    this.to = to;
	}

	public void union() {
	    berland.union(from, to);
	}
    }

    private static void print() {

	int size = closeds.size();
	System.out.println(size);
	Road closed;
	Road built;
	for (int i = 0; i < size; i++) {
	    closed = closeds.get(i);
	    built = buildeds.get(i);
	    System.out.format("%s %s %s %s\n", closed.from.node,
		    closed.to.node, built.from.node, built.to.node);
	}
    }

    private static void readRoads(Scanner scanner) {

	int l = n - 1;
	Road road;
	int key1;
	int key2;
	Node<Integer> from;
	Node<Integer> to;
	for (int i = 1; i <= l; i++) {
	    key1 = scanner.nextInt();
	    key2 = scanner.nextInt();
	    from = get(key1);
	    to = get(key2);
	    road = new Road(from, to);
	    if (connected(from, to)) {
		closeds.add(road);
	    } else {
		road.union();
	    }
	}
    }

    private static void buildRoads() {

	Node<Integer> first = get(1);
	Node<Integer> node;
	Road road;
	for (int i = 2; i <= n; i++) {
	    node = get(i);
	    if (!connected(first, node)) {
		road = new Road(first, node);
		road.union();
		buildeds.add(road);
	    }
	}
    }

    @SuppressWarnings("unchecked")
    public static void main(String[] args) {

	Scanner scanner = new Scanner(System.in);
	try {
	    n = scanner.nextInt();
	    int m = n + 1;
	    cities = (Node<Integer>[]) Array.newInstance(Node.class, m);
	    readRoads(scanner);
	    buildRoads();
	    print();
	} finally {
	    scanner.close();
	}
    }
}