#include <bits/stdc++.h>
int dsu[1000];
int find(int i) { return dsu[i] < 0 ? i : (dsu[i] = find(dsu[i])); }
int join(int i, int j) {
  i = find(i);
  j = find(j);
  if (i == j) return 0;
  if (dsu[i] > dsu[j])
    dsu[i] = j;
  else {
    if (dsu[i] == dsu[j]) dsu[i]--;
    dsu[j] = i;
  }
  return 1;
}
int main() {
  static int ii[1000], jj[1000];
  int n, h, i, j, cnt;
  scanf("%d", &n);
  memset(dsu, -1, n * sizeof *dsu);
  cnt = 0;
  for (h = 0; h < n - 1; h++) {
    scanf("%d%d", &i, &j), i--, j--;
    if (!join(i, j)) ii[cnt] = i, jj[cnt] = j, cnt++;
  }
  printf("%d\n", cnt);
  for (j = 0; j < n; j++)
    if (join(0, j)) {
      cnt--;
      printf("%d %d 1 %d\n", ii[cnt] + 1, jj[cnt] + 1, j + 1);
    }
  return 0;
}
