#include <bits/stdc++.h>
using namespace std;
bool mark[1001], used[1001][1001];
vector<pair<int, int> > cycleEdges;
vector<int> comps, adj[1001], trees;
int n;
void dfs(int v, int father, int lastV) {
  mark[v] = true;
  for (__typeof(((int)((adj[v]).size())) - 1) i = (0);
       i <= (((int)((adj[v]).size())) - 1); i++)
    if (!mark[adj[v][i]])
      dfs(adj[v][i], father, v);
    else if (adj[v][i] != lastV && !used[adj[v][i]][v]) {
      used[v][adj[v][i]] = true;
      cycleEdges.push_back(make_pair(v, adj[v][i]));
    }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (__typeof(n - 1) i = (1); i <= (n - 1); i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (__typeof(n) i = (1); i <= (n); i++)
    if (!mark[i]) {
      comps.push_back(i);
      dfs(i, i, i);
    }
  cout << ((int)((cycleEdges).size())) << endl;
  for (__typeof(((int)((cycleEdges).size())) - 1) i = (0);
       i <= (((int)((cycleEdges).size())) - 1); i++)
    cout << cycleEdges[i].first << " " << cycleEdges[i].second << " "
         << comps[i] << " " << comps[i + 1] << endl;
  return 0;
}
