#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<pair<int, int>> rem;
vector<int> vis(1005), comp(1005);
void dfs(int s, int p, vector<int> adj[]) {
  vis[s] = 1;
  for (int i = 0; i < adj[s].size(); i++) {
    if (adj[s][i] != p) {
      if (vis[adj[s][i]] == 0) {
        dfs(adj[s][i], s, adj);
      } else if (vis[adj[s][i]] == 1) {
        rem.push_back({s, adj[s][i]});
      }
    }
  }
  vis[s] = 2;
}
int main() {
  int n;
  cin >> n;
  vector<int> adj[n + 1];
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int num = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      comp[num++] = i;
      dfs(i, 0, adj);
    }
  }
  cout << num - 1 << endl;
  for (int i = 0; i < num - 1; i++) {
    cout << rem[i].first << " " << rem[i].second << " " << comp[i] << " "
         << comp[i + 1] << endl;
  }
}
