#include <bits/stdc++.h>
const int maxn = 1001;
int pa[maxn];
struct Node {
  int u, v;
} cut[maxn];
int finding(int x) {
  if (x != pa[x]) {
    pa[x] = finding(pa[x]);
  }
  return pa[x];
}
void unio(int a, int b) {
  int x = finding(a);
  int y = finding(b);
  pa[x] = y;
}
int main() {
  int n, ans = 0;
  scanf("%d", &n);
  for (int i = 0; i <= n; i++) {
    pa[i] = i;
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (finding(a) == finding(b)) {
      cut[ans].u = a;
      cut[ans].v = b;
      ans++;
    } else {
      unio(a, b);
    }
  }
  printf("%d\n", ans);
  int num = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (finding(i) != finding(j)) {
        printf("%d %d %d %d\n", cut[num].u, cut[num].v, i, j);
        unio(i, j);
        num++;
        if (num == ans) break;
      }
    }
  }
}
