#include <bits/stdc++.h>
using namespace std;
int P[111111], R[111111];
int find(int x) {
  if (P[x] != x) P[x] = find(P[x]);
  return P[x];
}
bool Union(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return true;
  if (R[x] > R[y])
    P[y] = x;
  else {
    P[x] = y;
    if (R[x] == R[y]) R[y]++;
  }
  return false;
}
vector<pair<int, int> > dels;
set<int> comps;
int main() {
  int N;
  cin >> N;
  int u, v;
  for (int i = 1; i <= N; i++) P[i] = i;
  for (int i = 1; i < N; i++) {
    scanf("%d %d", &u, &v);
    if (Union(u, v)) dels.push_back({u, v});
  }
  for (int i = 1; i <= N; i++) comps.insert(find(i));
  int i = 0;
  cout << dels.size() << endl;
  for (set<int>::iterator it = comps.begin(); i < dels.size(); i++, it) {
    printf("%d %d %d %d\n", dels[i].first, dels[i].second, *(++it), *it);
  }
}
