#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v;
} del[4000];
struct data {
  int u, v, x, y;
} lms[4000];
int fa[1013], sum[1013], tot, n, x, y, fx, fy, ans;
inline int find(int x) {
  if (fa[x] == x) return x;
  fa[x] = find(fa[x]);
  return fa[x];
}
inline long long read() {
  long long cnt = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    cnt = cnt * 10 + ch - 48;
    ch = getchar();
  }
  return cnt * f;
}
void load() {
  for (int i = 1; i <= n; i++) fa[i] = i;
}
int main() {
  n = read();
  load();
  for (int i = 1; i < n; i++) {
    x = read();
    y = read();
    fx = find(x);
    fy = find(y);
    if (fx != fy)
      fa[fy] = fx;
    else {
      del[++tot].u = x;
      del[tot].v = y;
    }
  }
  for (int i = 1; i < n; i++)
    for (int j = i + 1; j <= n; j++) {
      fx = find(i);
      fy = find(j);
      if (fx != fy) {
        fa[fy] = fx;
        lms[++ans].u = del[tot].u;
        lms[ans].v = del[tot--].v;
        lms[ans].x = i;
        lms[ans].y = j;
      }
    }
  printf("%d\n", ans);
  for (int i = 1; i <= ans; i++)
    printf("%d %d %d %d\n", lms[i].u, lms[i].v, lms[i].x, lms[i].y);
  return 0;
}
