#include <bits/stdc++.h>
using namespace std;
int t[1005], k, n, m, x, y, T, tx, ty, ti;
pair<int, int> second[50005];
pair<pair<int, int>, pair<int, int> > sol[1005];
ifstream F(".in");
int Find(int x) {
  int r, y;
  for (r = x; r != t[r]; r = t[r])
    ;
  while (x != t[x]) {
    y = t[x];
    t[x] = r;
    x = y;
  }
  return r;
}
void Unite(int x, int y) {
  if (t[x] < t[y])
    t[y] = t[x];
  else
    t[x] = t[y];
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) t[i] = i;
  while (cin >> x >> y) {
    tx = Find(x);
    ty = Find(y);
    if (tx != ty)
      Unite(tx, ty);
    else
      second[++m] = {x, y};
  }
  T = Find(1);
  m = 0;
  for (int i = 2; i <= n; ++i) {
    ti = Find(i);
    if (T != ti) {
      Unite(1, ti);
      sol[++k] = {second[++m], {T, ti}};
    }
  }
  cout << k << '\n';
  for (int i = 1; i <= k; ++i) {
    cout << sol[i].first.first << " " << sol[i].first.second << " "
         << sol[i].second.first << " " << sol[i].second.second << '\n';
  }
  return 0;
}
