#include <bits/stdc++.h>
using namespace std;
int n, x, y, u, v, par[100001];
queue<pair<int, int> > pr;
int FND(int p) { return (p == par[p]) ? p : par[p] = FND(par[p]); }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) par[i] = i;
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    u = FND(x);
    v = FND(y);
    if (u != v) {
      par[u] = v;
    } else {
      pr.push(make_pair(x, y));
    }
  }
  cout << pr.size() << endl;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      u = FND(i);
      v = FND(j);
      if (u != v) {
        par[u] = v;
        cout << pr.front().first << " " << pr.front().second << " " << i << " "
             << j << endl;
        pr.pop();
      }
    }
  }
}
