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;
void optimise() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
long long int mod = (long long int)1e9 + 7;
void normalize(long long int &a) { a = (a + mod) % mod; }
long long int modmul(long long int a, long long int b) {
  a = a % mod;
  b = b % mod;
  normalize(a);
  normalize(b);
  return (a * b) % mod;
}
long long int modadd(long long int a, long long int b) {
  a = a % mod;
  b = b % mod;
  normalize(a);
  normalize(b);
  return (a + b) % mod;
}
long long int modsub(long long int a, long long int b) {
  a = a % mod;
  b = b % mod;
  normalize(a);
  normalize(b);
  return (a - b + mod) % mod;
}
long long int me(long long int x, long long int n) {
  x %= mod;
  if (n == 0) return 1;
  long long int u = me(x, n / 2) % mod;
  u = (u * u) % mod;
  if (n % 2) u = (u * x) % mod;
  return u;
}
long long int me1(long long int x, long long int n) {
  if (n == 0) return 1;
  long long int u = me1(x, n / 2);
  u = u * u;
  if (n % 2) u = u * x;
  return u;
}
inline long long int modInv(long long int a) { return me(a, mod - 2); }
inline long long int modDiv(long long int a, long long int b) {
  return modmul(a, modInv(b));
}
float power(float x, long long int y) {
  float temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else {
    if (y > 0)
      return x * temp * temp;
    else
      return (temp * temp) / x;
  }
}
long long int __gcd(long long int a, long long int b) {
  if (b == 0)
    return a;
  else
    return __gcd(b, a % b);
}
pair<long long int, long long int> operator+(
    pair<long long int, long long int> a,
    pair<long long int, long long int> b) {
  return {a.first + b.first, a.second + b.second};
}
pair<long long int, long long int> operator-(
    pair<long long int, long long int> a,
    pair<long long int, long long int> b) {
  return {a.first - b.first, a.second - b.second};
}
pair<long long int, long long int> operator*(
    pair<long long int, long long int> a,
    pair<long long int, long long int> b) {
  return {a.first * b.first, a.second * b.second};
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  for (auto it : v) os << it << " ";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (long long int i = 0; i < v.size(); ++i) os << v[i] << " ";
  return os;
}
const long long int N = 1e3 + 1;
vector<long long int> vis(N);
vector<long long int> G[N];
vector<long long int> parent(N);
map<pair<long long int, long long int>, long long int> s;
long long int g;
void dfs(long long int v, long long int p) {
  vis[v] = 1;
  for (auto y : G[v]) {
    if (vis[y] and p != y and s.find({v, y}) == s.end() and
        s.find({y, v}) == s.end()) {
      s[{v, y}] = g;
    } else if (vis[y] == 0) {
      dfs(y, v);
    }
  }
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> size1(n + 1);
  for (long long int i = 0; i < n - 1; i++) {
    long long int x, y;
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  set<long long int> ans;
  for (long long int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      g = i;
      dfs(i, -1);
      if (i != 1) ans.insert(i);
    }
  }
  vector<pair<pair<long long int, long long int>,
              pair<long long int, long long int> > >
      p1;
  while (!ans.empty()) {
    auto k1 = *s.begin();
    auto k2 = *ans.begin();
    p1.push_back({{k1.first}, {k2, 1}});
    s.erase(s.begin());
    ans.erase(k2);
  }
  cout << p1.size() << "\n";
  for (long long int i = 0; i < p1.size(); i++) {
    cout << p1[i].first.first << " " << p1[i].first.second << " "
         << p1[i].second.first << " " << p1[i].second.second << "\n";
  }
}
signed main() {
  optimise();
  long long int t;
  t = 1;
  cout << fixed << setprecision(3);
  while (t--) {
    solve();
    cout << "\n";
  }
  cerr << "\n"
       << "Time Elasped : " << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
}