#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int p[N];
bool f[N];
int find(int x) {
  if (p[x] != x) p[x] = find(p[x]);
  return p[x];
}
void init() {
  for (int i = 0; i < N; i++) p[i] = i;
}
vector<int> v;
vector<pair<int, int> > s;
int main(void) {
  int n;
  cin >> n;
  init();
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    if (find(a) == find(b))
      s.push_back({a, b});
    else
      p[find(a)] = find(b);
  }
  for (int i = 1; i <= n; i++) {
    if (f[find(i)] == 0) {
      f[find(i)] = 1;
      v.push_back(find(i));
    }
  }
  cout << s.size() << endl;
  for (int i = 0; i < s.size(); i++) {
    cout << s[i].first << " " << s[i].second << " " << v[i] << " " << v[i + 1]
         << endl;
  }
  return 0;
}
