#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vlli = vector<long long int>;
using vpii = vector<pair<int, int>>;
int n, u, v, x, idx = 1;
vvi adj;
vi a;
set<pii> edges;
vb visit;
void dfs(int u, int prev) {
  visit[u] = true;
  for (auto v : adj[u])
    if (v != prev) {
      if (!visit[v])
        dfs(v, u);
      else
        edges.insert(make_pair(min(u, v), max(u, v)));
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  adj.resize(n + 1);
  visit.assign(n + 1, false);
  for (int i = 1; i < n; i++)
    cin >> u >> v, adj[u].push_back(v), adj[v].push_back(u);
  for (int i = 1; i <= n; i++)
    if (!visit[i]) a.push_back(i), dfs(i, -1);
  cout << a.size() - 1 << '\n';
  for (auto i : edges)
    cout << i.first << " " << i.second << " " << a[idx] << " " << a[idx - 1]
         << '\n',
        idx++;
}
