#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, l, sum = 0, flag = 0, t, m, ans = 0, parent[100005];
vector<pair<long long int, long long int> > bekaar, achha;
void make_set(int n) {
  for (int i = 1; i <= n; i++) parent[i] = i;
}
int find_set(int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void merge_set(int uu, int vv) {
  int u = find_set(uu);
  int v = find_set(vv);
  if (u == v) {
    bekaar.push_back({uu, vv});
    return;
  }
  parent[u] = v;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  make_set(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> j >> k;
    merge_set(j, k);
  }
  int prev = -1;
  for (int i = 1; i <= n; i++) {
    if (parent[i] == i) {
      if (prev != -1) achha.push_back({prev, i});
      prev = i;
    }
  }
  cout << achha.size() << '\n';
  for (int i = 0; i < bekaar.size(); i++) {
    cout << bekaar[i].first << " " << bekaar[i].second << " " << achha[i].first
         << " " << achha[i].second << '\n';
  }
  return 0;
}
