#include <bits/stdc++.h>
using namespace std;
const int N = 1009;
int n, s[N];
int f[N];
pair<int, int> d[N];
void Init() {
  for (int i = 1; i <= n; i++) s[i] = i;
}
int Find(int x) {
  if (x != s[x]) s[x] = Find(s[x]);
  return s[x];
}
void Union(int x, int y) {
  x = Find(x);
  y = Find(y);
  s[x] = s[y];
}
int main() {
  scanf("%d", &n);
  Init();
  int cnt = 0;
  int tot = 0;
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (Find(x) != Find(y))
      Union(x, y);
    else
      d[++cnt] = make_pair(x, y);
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= n; i++)
    if (s[i] == i) f[++tot] = i;
  int now = 1;
  for (int i = 1; i <= cnt; i++) {
    printf("%d %d %d %d\n", d[i].first, d[i].second, f[tot], f[now]);
    now++;
  }
  return 0;
}
