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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long int nodes_size;
long long int edge_size;
class edge {
 public:
  long long int node;
  long long int cost;
  edge(long long int i, long long int j) {
    node = i;
    cost = j;
  }
};
class graph {
 public:
  long long int node;
  vector<edge> edges;
  long long int parent;
  long long int cost;
  vector<long long int> children;
} nodes[1005];
long long int visited[1005];
class point {
 public:
  long long int x;
  long long int y;
  point() {}
  point(long long int i, long long int j) {
    x = i;
    y = j;
  }
};
void fill_array(long long int ar[], long long int value, long long int size) {
  for (long long int i = 0; i < size; i++) ar[i] = value;
}
void print_ll_vector(vector<long long int> v) {
  for (long long int i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << endl;
}
void input_graph(bool is_undirected, bool is_cost) {
  cin >> nodes_size;
  edge_size = nodes_size - 1;
  for (long long int i = 0; i < edge_size; i++) {
    long long int a, b, c;
    cin >> a >> b;
    if (is_cost) {
      cin >> c;
      nodes[a].edges.push_back(edge(b, c));
      if (is_undirected) nodes[b].edges.push_back(edge(a, c));
    } else {
      nodes[a].edges.push_back(edge(b, 1));
      if (is_undirected) nodes[b].edges.push_back(edge(a, 1));
    }
  }
}
vector<pair<long long int, long long int> > destroyed_edges;
long long int ctr = 0, c;
vector<long long int> ans;
void dfs(long long int node, long long int parent) {
  visited[node] = 1;
  for (long long int i = 0; i < nodes[node].edges.size(); i++) {
    if (nodes[node].edges[i].node != parent) {
      if (visited[nodes[node].edges[i].node]) {
        if (node > nodes[node].edges[i].node) {
          if (c > 0 || ctr == 1) {
            destroyed_edges.push_back(
                make_pair(node, nodes[node].edges[i].node));
            c++;
          } else {
            c++;
            ans.push_back(node);
            ans.push_back(nodes[node].edges[i].node);
          }
        }
      } else
        dfs(nodes[node].edges[i].node, node);
    }
  }
}
vector<long long int> new_edges;
int main() {
  input_graph(true, false);
  fill_array(visited, 0, nodes_size + 1);
  for (long long int i = 1; i <= nodes_size; i++) {
    if (!visited[i]) {
      c = 0;
      ctr++;
      dfs(i, -1);
      if (c == 0 && i != 1) new_edges.push_back(i);
    }
  }
  cout << (ans.size() / 2) + new_edges.size() << endl;
  for (long long int i = 0; i < ans.size();) {
    cout << ans[i] << " " << ans[i + 1] << " " << ans[i] << " " << 1 << endl;
    i = i + 2;
  }
  for (long long int i = 0; i < new_edges.size(); i++)
    cout << destroyed_edges[i].first << " " << destroyed_edges[i].second << " "
         << destroyed_edges[i].first << " " << new_edges[i] << endl;
  return 0;
}