#include <bits/stdc++.h>
using namespace std;
int n, a[1005], par[1005];
vector<pair<int, int> > v;
vector<int> v1;
void init() {
  for (int i = 0; i <= n; ++i) par[i] = i;
}
int parent(int x) {
  if (par[x] == x) return x;
  return par[x] = parent(par[x]);
}
bool join(int x, int y) {
  x = parent(x);
  y = parent(y);
  if (x == y) return 0;
  par[x] = y;
  return 1;
}
int main() {
  cin >> n;
  init();
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (!join(x, y)) {
      v.push_back({x, y});
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (par[i] == i) {
      v1.push_back(i);
    }
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); ++i) {
    printf("%d %d %d %d\n", v[i].first, v[i].second, v1[i], v1[i + 1]);
  }
}
