#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 5;
int parent[MAXN];
vector<pair<int, int> > res, res2;
set<int> st;
int find_set(int v) {
  if (v == parent[v])
    return v;
  else
    return parent[v] = find_set(parent[v]);
}
int main() {
  int n;
  int a, b;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) parent[i] = i;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &a, &b);
    int aa = find_set(a);
    int bb = find_set(b);
    if (aa != bb) {
      parent[bb] = aa;
    } else {
      res.push_back(make_pair(a, b));
    }
  }
  int ans = res.size();
  printf("%d\n", ans);
  int p = find_set(1);
  for (int i = 2; i <= n; i++) {
    int temp = find_set(i);
    if (temp != p && st.count(temp) == 0) {
      res2.push_back(make_pair(i, 1));
      st.insert(temp);
    }
  }
  for (int i = 0; i < ans; i++) {
    printf("%d %d %d %d\n", res[i].first, res[i].second, res2[i].first,
           res2[i].second);
  }
  return 0;
}
