#include <bits/stdc++.h>
using namespace std;
struct dsu {
  vector<int> id, size;
  dsu(int n) {
    id = vector<int>(n);
    size = vector<int>(n, 1);
    iota(id.begin(), id.end(), 0);
  }
  int find(int x) { return id[x] == x ? x : id[x] = find(id[x]); }
  bool join(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return false;
    if (size[x] < size[y]) swap(x, y);
    id[y] = x;
    size[x] += size[y];
    return true;
  }
};
int main() {
  int n;
  scanf("%d", &n);
  dsu berland(n);
  vector<pair<int, int> > closed;
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    if (!berland.join(u - 1, v - 1)) closed.emplace_back(u, v);
  }
  vector<int> parents;
  for (int i = 0; i < n; ++i)
    if (berland.id[i] == i) parents.push_back(i + 1);
  int m = (int)closed.size();
  printf("%d\n", m);
  assert(closed.size() == parents.size() - 1);
  for (int i = 0; i < m; ++i)
    printf("%d %d %d %d\n", closed[i].first, closed[i].second, parents[i],
           parents[i + 1]);
  return 0;
}
