#include <bits/stdc++.h>   using namespace std;   int A;   int gcd(int a, int b) {     if (a < b) swap(a, b);     if (a % b == 0) return b;     return gcd(b, a % b);   }   pair<int, int> find(vector<pair<int, int> > &sets, int a) {     if (sets[a].first != a) sets[a].first = find(sets, sets[a].first).first;     return sets[a];   }   void unions(vector<pair<int, int> > &sets, int a, int b) {     pair<int, int> p = find(sets, a);     pair<int, int> q = find(sets, b);     if (p.second < q.second) swap(p, q);     sets[q.first].first = p.first;     if (p.second == q.second) sets[p.first].second++;   }   void solve() {     long long int n, i, a, b, x, y, a1, b1;     cin >> n;     vector<pair<int, int> > sets(n, {0, 1});     pair<int, int> p;     for (i = 0; i < n; i++) sets[i].first = i;     vector<pair<int, pair<int, int> > > v;     for (i = 0; i < n - 1; i++) {       cin >> a >> b;       a--;       b--;       p = find(sets, a);       a1 = p.first;       x = p.second;       p = find(sets, b);       b1 = p.first;       y = p.second;       if (a1 != b1)         unions(sets, a1, b1);       else {         v.push_back({a1, {a + 1, b + 1}});       }     }     set<int> s;     for (i = 0; i < n; i++) {       s.insert(find(sets, sets[i].first).first);     }     auto itr = s.begin();     x = *itr + 1;     itr++;     cout << v.size() <<   n ;     for (i = 0, itr; i < v.size(); i++, itr++)       cout << v[i].second.first <<     << v[i].second.second <<     << x <<                << *itr + 1 <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int T = 1;     while (T--) {       solve();     }     return 0;   }   