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