#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int INF = int(1e9) + 10;
int n, m, h[N], col[N], len, l;
int u[N], v[N], it;
pair<int, int> need[N];
pair<pair<int, int>, pair<int, int> > ans[N];
int find(int v) {
  if (v == col[v]) return v;
  col[v] = find(col[v]);
  return col[v];
}
void unite(int A, int B) {
  int a = find(A);
  int b = find(B);
  if (a == b) need[++len] = make_pair(A, B);
  if (a != b) {
    if (h[a] < h[b]) swap(a, b);
    col[b] = a;
    if (h[a] == h[b]) h[a]++;
  }
}
int main() {
  int u, v;
  cin >> n;
  for (int i = 1; i <= n; ++i) col[i] = i;
  for (int i = 1; i <= n - 1; ++i) {
    cin >> u >> v;
    unite(u, v);
  }
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      if (find(i) != find(j)) {
        ans[++l] = make_pair(need[++it], make_pair(i, j));
        unite(i, j);
      }
  cout << l << endl;
  for (int i = 1; i <= l; ++i)
    cout << ans[i].first.first << ' ' << ans[i].first.second << ' '
         << ans[i].second.first << ' ' << ans[i].second.second << '\n';
}
