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.*;


public class D
{
   public static void main(String[] args)
   {
      new D(new Scanner(System.in));
   }

   public D(Scanner in)
   {
      int N = in.nextInt();
      
      Graph g = new Graph(N);

      // Read in the graph
      for (int u=1; u<N; u++)
      {
         int i=in.nextInt()-1;
         int j=in.nextInt()-1;
         g.addEdge(u, i, j);
      }

      // Create teh solvers
      Connected ccs = new Connected(g.N);
      BridgeFinder bf = new BridgeFinder(g.N);

      // Solve
      ArrayList<Pair> res = new ArrayList<Pair>();
      while (true)
      {
         ArrayList<Integer> cmps = ccs.solve(g);
         if (cmps.size() <= 1) break;

         // Cut something that not a bridge and make a new edge
         bf.solve(g);
         int id = -1;
         for (int u=1; u<N; u++)
            if (!bf.isBridge[u])
            {
               id = u;
               break;
            }

         ArrayList<Integer> be = g.removeEdge(id);
         g.addEdge(id, cmps.get(0), cmps.get(1));
         res.add(new Pair(cmps.get(0)+1, cmps.get(1)+1, 
                          be.get(0)+1, be.get(1)+1));
      }

      System.out.printf("%d%n", res.size());
      for (Pair p : res)
         System.out.println(p);
   }
}

class Pair
{
   ArrayList<Integer> vs = new ArrayList<Integer>(); 

   public Pair(int a, int b, int c, int d)
   {
      vs.add(c);
      vs.add(d);
      vs.add(a);
      vs.add(b);
   }

   public String toString()
   {
      StringBuilder sb = new StringBuilder();
      for (int v : vs)
      {
         sb.append(v);
         sb.append(' ');
      }
      return sb.toString().trim();
   }
}

class Edge
{
   int eid, v;

   public Edge(int id, int to)
   {
      eid = id; v = to;
   }
}

class Graph
{
   int N;
   ArrayList<Edge>[] g;

   public Graph(int n)
   {
      N = n;
      g = new ArrayList[N];
      for (int i=0; i<N; i++)
         g[i] = new ArrayList<Edge>();
   }

   void addEdge(int id, int i, int j)
   {
      g[i].add(new Edge(id, j));
      g[j].add(new Edge(id, i));
   }

   ArrayList<Integer> removeEdge(int id)
   {
      ArrayList<Integer> res = new ArrayList<Integer>();
      for (int i=0; i<N; i++)
      {
         for (int j=0; j<g[i].size(); j++)
         {
            Edge e = g[i].get(j);
            if (e.eid == id)
            {
               g[i].remove(j);
               res.add(i);
               break;
            }
         }
      }
      return res;
   }
}

class BridgeFinder
{
   int[] low;
   int[] pre;
   int cnt;
   boolean[] isBridge;

   public BridgeFinder(int n)
   {
      low = new int[n];
      pre = new int[n];
      isBridge = new boolean[n];
   }

   void solve(Graph g)
   {
      for (int v=0; v<g.N; v++)
         low[v] = pre[v] = -1;
      Arrays.fill(isBridge, false);

      for (int v=0; v<g.N; v++)
         if (pre[v] == -1)
            dfs(g, v, v);
   }

   void dfs(Graph g, int u, int v)
   {
      pre[v] = cnt++;
      low[v] = pre[v];
      for (Edge e : g.g[v])
      {
         if (pre[e.v] == -1)
         {
            dfs(g, v, e.v);
            low[v] = Math.min(low[v], low[e.v]);
            if (low[e.v] == pre[e.v])
               isBridge[e.eid] = true;
         }
         else if (e.v != u)
            low[v] = Math.min(low[v], pre[e.v]);
      }
   }
}

class Connected
{
   boolean[] visited;

   public Connected(int N)
   {
      visited = new boolean[N];
   }

   ArrayList<Integer> solve(Graph g)
   {
      ArrayList<Integer> res = new ArrayList<Integer>();
      Arrays.fill(visited, false);
      
      for (int i=0; i<g.N; i++)
         if (!visited[i])
         {
            res.add(i);
            dfs(g, i);
         }
      return res;
   }

   void dfs(Graph g, int i)
   {
      if (visited[i]) return;
      visited[i] = true;
      for (Edge e : g.g[i])
         dfs(g, e.v);
   }
}