#include <bits/stdc++.h>
using namespace std;
int pr[1005], sz[1005], ans = 0;
vector<pair<int, int> > vec;
int find_set(int u) {
  if (u == pr[u]) return u;
  return pr[u] = find_set(pr[u]);
}
void union_set(int u, int v) {
  int a = find_set(u);
  int b = find_set(v);
  if (a == b) {
    vec.push_back({u, v});
    ans++;
    return;
  }
  if (sz[a] < sz[b]) swap(a, b);
  sz[a] += sz[b];
  pr[b] = a;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    pr[i] = i;
    sz[i] = 1;
  }
  for (int i = 0; i < n - 1; i++) {
    int n1, n2;
    cin >> n1 >> n2;
    union_set(n1, n2);
  }
  set<int> s;
  for (int i = 1; i <= n; i++) {
    int u = find_set(i);
    s.insert(u);
  }
  cout << ans << endl;
  auto it = s.begin();
  for (int i = 0; i < ans; i++) {
    cout << vec[i].first << " " << vec[i].second << " " << *it << " ";
    it++;
    cout << *it << endl;
  }
  return 0;
}
