#include <bits/stdc++.h>
using namespace std;
int par[1001];
int A[1001], B[1001];
int n;
void link(int a, int b) {
  int temp = par[a];
  for (int i = 1; i <= n; i++) {
    if (par[i] == temp) par[i] = par[b];
  }
}
int main() {
  int a, b, k = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    par[i] = i;
  }
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    if (par[a] == par[b]) {
      A[k] = a;
      B[k] = b;
      k++;
    } else {
      link(a, b);
    }
  }
  printf("%d\n", k);
  for (int j = 0; j < k; j++) {
    for (int i = 1; i <= n; i++) {
      if (par[i] != par[A[j]]) {
        printf("%d %d %d %d\n", A[j], B[j], A[j], i);
        link(A[j], i);
        break;
      }
    }
  }
  return 0;
}
