#include <bits/stdc++.h>
using namespace std;
int v[1000];
int parent[1000];
int r[1000];
void make_set(int v) {
  parent[v] = v;
  r[v] = 0;
}
int find_set(int v) {
  if (parent[v] == v) {
    return v;
  }
  return parent[v] = find_set(parent[v]);
}
void make_pair(int a, int b) {
  int pa = find_set(a);
  int pb = find_set(b);
  if (r[pa] < r[pb]) {
    swap(pa, pb);
  }
  parent[pb] = pa;
  r[pa] = r[pa] + r[pb];
}
int main() {
  int t;
  cin >> t;
  int k = t;
  for (int i = 0; i < t; i++) {
    make_set(i);
  }
  int y[t], z[t];
  int counter = 0;
  t--;
  while (t--) {
    int a, b;
    cin >> a >> b;
    if (find_set(a - 1) != find_set(b - 1)) {
      make_pair(a - 1, b - 1);
    } else {
      y[counter] = a;
      z[counter] = b;
      counter++;
    }
  }
  counter--;
  if (counter == -1) {
    cout << 0;
    return 0;
  }
  cout << counter + 1 << endl;
  for (int i = 1; i < k; i++) {
    if (find_set(i) != find_set(0)) {
      cout << y[counter] << " " << z[counter] << " " << i + 1 << " " << 1
           << endl;
      counter--;
      make_pair(i, 0);
    }
  }
  return 0;
}
