#include <bits/stdc++.h>
using namespace std;
const int mxn = 1e3 + 5;
const int mod = 1e9 + 7;
const int mod1 = 998244353;
vector<int> par(mxn);
int find_set(int a) {
  if (a == par[a]) return a;
  return par[a] = find_set(par[a]);
}
bool union_set(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a == b) return 0;
  par[b] = a;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, a, b, i;
  cin >> n;
  for (i = 1; i <= n; i++) par[i] = i;
  vector<pair<int, int> > x;
  vector<int> r;
  for (i = 1; i < n; i++) {
    cin >> a >> b;
    if (!union_set(a, b)) x.push_back(make_pair(a, b));
  }
  for (i = 1; i <= n; i++)
    if (par[i] == i) r.push_back(i);
  cout << (int)x.size() << endl;
  for (i = 1; i < (int)r.size(); i++) {
    cout << x[i - 1].first << " " << x[i - 1].second << " " << r[i - 1] << " "
         << r[i] << endl;
  }
}
