#include <bits/stdc++.h>
using namespace std;
int parent[2000];
queue<pair<int, int> > close;
int i, n, t, a, b;
int dsu_find(int v) {
  if (parent[v] == v) return v;
  parent[v] = dsu_find(parent[v]);
  return parent[v];
}
bool dsu_unite(int a, int b) {
  a = dsu_find(a);
  b = dsu_find(b);
  if (a == b) return false;
  if (rand() & 1)
    parent[a] = parent[b];
  else
    parent[b] = parent[a];
  return true;
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) parent[i] = i;
  for (i = 1; i < n; i++) {
    cin >> a >> b;
    if (!dsu_unite(a, b)) {
      close.push(make_pair(a, b));
      t++;
    }
  }
  cout << t << "\n";
  for (i = 2; i <= n; i++)
    if (dsu_unite(1, i)) {
      cout << close.front().first << " " << close.front().second << " " << 1
           << " " << i << "\n";
      close.pop();
    }
  return 0;
}
