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 M = 1000000007;
long long int min(long long int a, long long int b, long long int c,
                  long long int d) {
  long long int arr[4] = {a, b, c, d};
  sort(arr, arr + 4);
  return arr[0];
}
long long int max(long long int a, long long int b, long long int c,
                  long long int d) {
  long long int arr[4] = {a, b, c, d};
  sort(arr, arr + 4);
  return arr[3];
}
long long int gcd(long long int a, long long int b) {
  if (b < a) {
    int temp = a;
    a = b;
    b = temp;
  }
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
  return (a * b / gcd(a, b));
}
vector<long long int> getprimes() {
  vector<long long int> pl(101, 1);
  for (int i = 2; i <= 100; i++) {
    if (pl[i] == 1) {
      for (int j = 2 * i; j <= 100; j += i) {
        pl[j] = 0;
      }
    }
  }
  return pl;
}
double distsqrd(double x1, double y1, double x2, double y2) {
  return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
}
long long int fact(long long int first) {
  long long int ans = 1;
  if (first == 0) {
    return 1;
  }
  while (first > 0) {
    ans = (ans * first) % 1000000007;
    first--;
  }
  return ans % 1000000007;
}
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      ans *= a;
      ans = ans;
    }
    b /= 2;
    a *= a;
    a = a;
  }
  return ans;
}
vector<int> getbinary(int first) {
  vector<int> bin(16, 0);
  int iter = 0;
  while (first > 0) {
    if (first % 2 == 1) {
      bin[iter] = 1;
    } else {
      bin[iter] = 0;
    }
    iter++;
    first /= 2;
  }
  return bin;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  map<int, vector<int> > g;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> col(n + 1, 0);
  int parent[n + 1];
  vector<int> scc;
  vector<pair<int, int> > nreq;
  stack<int> s;
  map<pair<int, int>, int> m1;
  for (int i = 1; i <= n; i++) {
    if (col[i] == 0) {
      parent[i] = -1;
      col[i] = 1;
      scc.push_back(i);
      s.push(i);
      while (!s.empty()) {
        int u = s.top();
        s.pop();
        for (auto v : g[u]) {
          if (col[v] == 1) {
            if (v != parent[u] && u != parent[v] && m1[make_pair(u, v)] == 0) {
              nreq.push_back(make_pair(u, v));
              m1[make_pair(u, v)] = 1;
              m1[make_pair(v, u)] = 1;
            }
          } else {
            parent[v] = u;
            col[v] = 1;
            s.push(v);
          }
        }
      }
    }
  }
  n = scc.size();
  cout << n - 1 << endl;
  for (int i = 0; i < n - 1; i++) {
    cout << nreq[i].first << " " << nreq[i].second << " " << scc[i] << " "
         << scc[i + 1] << endl;
  }
}