#include <bits/stdc++.h>
const int N = 1000 + 10;
int n, fa[N], ans[N * 2];
int getf(int x) {
  for (; x != fa[x]; x = fa[x] = fa[fa[x]])
    ;
  return x;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int fx = getf(x), fy = getf(y);
    if (fx != fy)
      fa[fx] = fy;
    else
      ans[++*ans] = x, ans[++*ans] = y;
  }
  printf("%d\n", ans[0] >> 1);
  for (int i = 2; i <= n; i++)
    if (getf(i) != getf(1))
      fa[getf(i)] = getf(1),
      printf("%d %d %d %d\n", ans[ans[0]--], ans[ans[0]--], 1, i);
}
