#include <bits/stdc++.h>
using namespace std;
const long long maxn = 300909;
const long long maxN = 2e6 + 7;
const long long oo = UINT_MAX;
const long long mod = 1e9 + 7;
long long n;
vector<pair<long long, long long> > vc;
long long par[maxn];
long long find(long long x) {
  if (par[x] < 0)
    return x;
  else
    return par[x] = find(par[x]);
}
bool comp(long long x, long long y) { return find(x) == find(y); }
void uni(long long x, long long y) {
  x = find(x);
  y = find(y);
  par[x] += par[y];
  par[y] = x;
}
vector<long long> vt;
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) par[i] = -1;
  for (long long i = 1; i <= n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    if (!comp(x, y))
      uni(x, y);
    else
      vc.push_back({x, y});
  }
  for (long long i = 1; i <= n; i++) {
    if (par[i] < 0) vt.push_back(i);
  }
  cout << vt.size() - 1 << "\n";
  for (long long i = 0; i < vt.size() - 1; i++) {
    cout << vc[i].first << " " << vc[i].second << " " << vt[i] << " "
         << vt[i + 1] << "\n";
  }
}
