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>
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9,
                  GOLD = ((1 + sqrt(5)) / 2);
long long keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
long long keyCount = sizeof(keymod) / sizeof(long long);
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcount(s);
}
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
long long n, a, b;
vector<set<long long>> adj(1007);
vector<bool> vis(1007, false);
vector<pair<long long, long long>> R, A;
long long Root = -1;
long long edgecnt = 0, vertexcnt = 0;
map<pair<long long, long long>, long long> Map;
void ccfind(long long z) {
  vis[z] = true;
  vertexcnt++;
  edgecnt += adj[z].size();
  for (auto it = adj[z].begin(); it != adj[z].end(); it++) {
    long long t = *it;
    if (!vis[t]) ccfind(t);
  }
}
void DFS(long long z, long long last) {
  vis[z] = true;
  for (auto it = adj[z].begin(); it != adj[z].end(); it++) {
    long long t = *it;
    if (t == last) continue;
    if (vis[t]) {
      if (Map[make_pair(z, t)] || Map[make_pair(t, z)]) continue;
      Map[make_pair(z, t)]++;
      Map[make_pair(t, z)]++;
      R.push_back(make_pair(z, t));
      continue;
    }
    DFS(t, z);
  }
}
void Input() {
  cin >> n;
  for (long long i = 1; i < n; i++) {
    cin >> a >> b;
    adj[a].insert(b);
    adj[b].insert(a);
  }
}
void Solve() {
  for (long long i = 1; i <= n; i++) {
    vertexcnt = 0;
    edgecnt = 0;
    if (vis[i]) continue;
    ccfind(i);
    if ((vertexcnt - 1) * 2 == edgecnt) {
      Root = i;
      break;
    }
  }
  for (long long i = 0; i < 1007; i++) vis[i] = false;
  ccfind(Root);
  for (long long i = 1; i <= n; i++) {
    if (vis[i]) continue;
    DFS(i, -1);
    A.push_back(make_pair(Root, i));
  }
  cout << R.size() << '\n';
  for (long long i = 0; i < R.size(); i++) {
    pair<long long, long long> x = R[i], y = A[i];
    cout << x.first << " " << x.second << " ";
    cout << y.first << " " << y.second << '\n';
  }
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ControlIO(argc, argv);
  Input();
  TimerStart();
  Solve();
  TimerStop();
  return 0;
}
void ControlIO(int argc, char* argv[]) {}
void TimerStart() {}
void TimerStop() {}
void Exit() {
  TimerStop();
  exit(0);
}