#include <bits/stdc++.h>
using namespace std;
int dsu[1010], rnk[1010], n;
bool bio[1010];
vector<pair<int, int> > delEdge, ress;
int root(int u) {
  while (dsu[u] != u) {
    dsu[u] = dsu[dsu[u]];
    u = dsu[u];
  }
  return u;
}
void connect(int u, int v) {
  if (root(u) != root(v)) {
    if (rnk[root(u)] <= rnk[root(v)]) {
      if (rnk[root(u)] == rnk[root(v)]) rnk[root(v)]++;
      dsu[root(u)] = root(v);
    } else
      dsu[root(v)] = root(u);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) dsu[i] = i, rnk[i] = 1;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    if (root(u) == root(v))
      delEdge.push_back({u, v});
    else
      connect(u, v);
  }
  int cnt = 0;
  bio[root(1)] = true;
  for (int i = 2; i <= n; i++) {
    if (!bio[root(i)]) {
      ress.push_back({root(1), i});
      connect(root(1), i);
      cnt++;
      bio[root(i)] = true;
    }
  }
  cout << delEdge.size() << endl;
  for (int i = 0; i < delEdge.size(); i++)
    cout << delEdge[i].first << " " << delEdge[i].second << " " << ress[i].first
         << " " << ress[i].second << endl;
}
