#include <bits/stdc++.h>
int dx[] = {0, -1, 0, 1, -1, 1, -1, 1};
int dy[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int N = 3e5 + 5, oo = 1e9, mod = 1e9 + 7;
const double pi = acos(-1);
using namespace std;
vector<int> g[N];
set<pair<int, int>> edges;
map<int, int> comp;
map<int, vector<int>> mp;
int scc;
bool vis[N];
void dfs(int node, int par) {
  vis[node] = true;
  comp[node] = scc;
  mp[scc].push_back(node);
  for (auto child : g[node]) {
    if (!vis[child])
      dfs(child, node);
    else if (child != par) {
      if (node > child)
        edges.insert({child, node});
      else
        edges.insert({node, child});
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      scc++;
      dfs(i, 0);
    }
  }
  cout << (int)(edges).size() << '\n';
  set<int> st, used;
  for (int i = 1; i <= scc; i++) st.insert(i);
  for (auto it : edges) {
    cout << it.first << ' ' << it.second << ' ';
    if (st.find(comp[it.first]) != st.end()) st.erase(comp[it.first]);
    if (used.find(comp[it.first]) != used.end() || used.empty()) {
      auto i = st.begin();
      cout << it.first << ' ' << mp[*i].back() << '\n';
      st.erase(i);
      used.insert(*i);
      used.insert(comp[it.first]);
    } else {
      auto i = used.begin();
      cout << it.first << ' ' << mp[*i].back() << '\n';
      used.insert(comp[it.first]);
      st.erase(comp[it.first]);
    }
  }
  return 0;
}
