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;
struct UnionFind {
  int n;
  vector<int> dad, size;
  UnionFind(int N) : n(N), dad(N), size(N, 1) {
    while (N--) dad[N] = N;
  }
  int find(int u) {
    if (dad[u] == u) return u;
    return dad[u] = find(dad[u]);
  }
  void join(int u, int v) {
    int Ru = find(u), Rv = find(v);
    if (Ru == Rv) return;
    if (size[Ru] > size[Rv]) swap(Ru, Rv);
    --n, dad[Ru] = Rv;
    size[Rv] += size[Ru];
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int get_size(int u) { return size[find(u)]; }
  int number_of_sets() { return n; }
};
const int MAXN = 1e3 + 5;
int n;
bool valid[MAXN];
int vis[MAXN];
vector<pair<int, int>> adj[MAXN];
bool dfs(int u, int p, tuple<int, int, int>& edge) {
  vis[u] = 1;
  for (auto e : adj[u]) {
    if (!valid[e.second] || e.first == p) continue;
    if (vis[e.first] == 1) {
      edge = make_tuple(u, e.first, e.second);
      return true;
    } else if (vis[e.first] == 2)
      continue;
    else if (dfs(e.first, u, edge))
      return true;
  }
  vis[u] = 2;
  return false;
}
int solve(UnionFind& UF, vector<pair<pair<int, int>, pair<int, int>>>& answer) {
  fill(valid, valid + n, true);
  int ans = UF.number_of_sets();
  while (UF.number_of_sets() > 1) {
    fill(vis, vis + n, 0);
    tuple<int, int, int> edge;
    for (int i = 0; i < n; i++) {
      if (vis[i]) continue;
      if (dfs(i, -1, edge)) break;
    }
    int u = UF.find(0);
    int v = u;
    for (int i = 0; i < n; i++) {
      v = UF.find(i);
      if (v != u) break;
    }
    UF.join(u, v);
    valid[get<2>(edge)] = false;
    answer.emplace_back(make_pair(get<0>(edge), get<1>(edge)), make_pair(u, v));
  }
  return ans - 1;
}
int main() {
  ;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  UnionFind UF(n);
  int _id = 0;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    UF.join(u, v);
    adj[u].emplace_back(v, _id);
    adj[v].emplace_back(u, _id);
    _id++;
  }
  vector<pair<pair<int, int>, pair<int, int>>> v;
  cout << solve(UF, v) << '\n';
  for (auto i : v)
    cout << i.first.first + 1 << ' ' << i.first.second + 1 << ' '
         << i.second.first + 1 << ' ' << i.second.second + 1 << '\n';
  return 0;
}