#include <bits/stdc++.h>
const int MAX_N = 1001;
int parent[MAX_N], depth[MAX_N];
int root(int x) {
  if (parent[x] != 0) return parent[x] = root(parent[x]);
  return x;
}
void join(int x, int y) {
  int root_x = root(x);
  int root_y = root(y);
  if (root_x == root_y) return;
  if (depth[root_x] < depth[root_y])
    parent[root_x] = root_y;
  else if (depth[root_y] < depth[root_x])
    parent[root_y] = root_x;
  else {
    parent[root_y] = root_x;
    ++depth[root_x];
  }
}
int main(void) {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(static_cast<std::ostream*>(nullptr));
  int n, a, b;
  std::vector<std::pair<int, int> > to_delete;
  std::cin >> n;
  for (int i = 1; i < n; ++i) {
    std::cin >> a >> b;
    if (root(a) != root(b))
      join(a, b);
    else
      to_delete.push_back(std::make_pair(a, b));
  }
  std::cout << to_delete.size() << std::endl;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (root(i) != root(j)) {
        std::cout << to_delete.back().first << " " << to_delete.back().second
                  << " " << i << " " << j << std::endl;
        to_delete.pop_back();
        join(i, j);
      }
    }
  }
  return 0;
}
