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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ATailouloute
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        QuickScanner in = new QuickScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, QuickScanner in, PrintWriter out) {
            int n = in.nextInt();
            DisjointSet ds = new DisjointSet(n);
            List<Integer>[] tree = CollectionsUtils.arrayOfListInteger(n);
            List<IntPair> ll = new ArrayList<>();
            for (int i = 1; i < n; i++) {
                int u = in.nextInt() - 1;
                int v = in.nextInt() - 1;
                if (!ds.connected(u, v)) {
                    tree[u].add(v);
                    tree[v].add(u);
                    ds.connect(u, v);
                } else {
                    ll.add(new IntPair(u, v));
                }
            }
            if (ll.isEmpty()) out.println(0);
            else {
                Set<Integer> roots = new HashSet<>();
                for (int i = 0; i < n; i++) {
                    roots.add(ds.root(i));
                }
                int last = -1;
                out.println(roots.size() - 1);
                Iterator<IntPair> it = ll.iterator();
                for (int r : roots) {
                    if (last != -1) {
                        IntPair pair = it.next();
                        out.printf("%d %d %d %d\n", pair.first + 1, pair.second + 1, r + 1, last + 1);
                    }
                    last = r;
                }
            }
        }

    }

    static class IntPair implements Comparable<IntPair> {
        public final int first;
        public final int second;

        public IntPair() {
            this(0, 0);
        }

        public IntPair(int u, int v) {
            this.first = u;
            this.second = v;
        }


        public int hashCode() {
            int hu = (int) (first ^ (first >>> 32));
            int hv = (int) (second ^ (second >>> 32));
            return 31 * hu + hv;
        }


        public boolean equals(Object obj) {
            IntPair pair = (IntPair) obj;
            return pair.first == first && pair.second == second;
        }


        public int compareTo(IntPair o) {
            return first == o.first ? Integer.compare(second, o.second) : Integer.compare(first, o.first);
        }


        public String toString() {
            return String.format("(%d,%d)", first, second);
        }

    }

    static class QuickScanner {
        BufferedReader br;
        StringTokenizer st;
        InputStream is;

        public QuickScanner(InputStream stream) {
            is = stream;
            br = new BufferedReader(new InputStreamReader(stream), 32768);
        }

        public String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

    }

    static class CollectionsUtils {
        public static List<Integer>[] arrayOfListInteger(int n) {
            List<Integer>[] ret = new List[n];
            for (int i = 0; i < n; i++) {
                ret[i] = new ArrayList<>();
            }
            return ret;
        }

    }

    static class DisjointSet {
        int[] ds;
        int[] rank;
        int count;

        public DisjointSet(int n) {
            ds = new int[n];
            rank = new int[n];
            count = n;
            for (int i = 0; i < n; i++) {
                ds[i] = i;
            }
        }

        public int root(int p) {
            if (p == ds[p]) return p;
            return (ds[p] = root(ds[p]));
        }

        public boolean connected(int p, int q) {
            return root(p) == root(q);
        }

        public void connect(int p, int q) {
            int rp = root(p);
            int rq = root(q);
            if (rp == rq) return;
            if (rank[rp] < rank[rq]) {
                ds[rp] = rq;
            } else if (rank[rp] > rank[rq]) {
                ds[rq] = rp;
            } else {
                ds[rq] = rp;
                rank[rp]++;
            }
            count--;
        }

    }
}