#include <bits/stdc++.h>
using namespace std;
int root[1001];
int find(int a) {
  if (root[a] == a) return a;
  return root[a] = find(root[a]);
}
void join(int a, int b) { root[find(a)] = find(b); }
int main() {
  int n;
  scanf("%d", &n);
  int i;
  for (i = 1; i < n; i++) root[i] = i;
  vector<pair<int, int> > inutil;
  int a, b;
  for (i = 1; i < n; i++) {
    scanf("%d %d", &a, &b);
    if (find(a) == find(b))
      inutil.push_back({a, b});
    else
      join(a, b);
  }
  printf("%d", inutil.size());
  int j = 0;
  for (i = 2; i <= n; i++) {
    if (find(i) != find(1)) {
      printf("\n%d %d %d %d", inutil[j].first, inutil[j].second, 1, i);
      join(i, 1);
      j++;
    }
  }
  return 0;
}
