#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_N = 1e3 + 9;
int par[MAX_N], rankv[MAX_N];
vector<pair<int, int>> cycles;
vector<array<int, 4>> ans;
void init(int n) {
  for (int i = 1; i <= n; i++) par[i] = i, rankv[i] = 1;
}
int find_set(int u) {
  if (par[u] == u) return u;
  return par[u] = find_set(par[u]);
}
void link(int x, int y) {
  if (rankv[x] > rankv[y]) swap(x, y);
  par[x] = y;
  rankv[y] += (rankv[y] == rankv[x]);
}
bool union_set(int x, int y) {
  x = find_set(x), y = find_set(y);
  if (x != y) link(x, y);
  return x != y;
}
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, u, v;
  cin >> n;
  init(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    if (!union_set(u, v)) cycles.push_back({u, v});
  }
  for (int i = 0; i < cycles.size(); i++) {
    auto cur = cycles[i];
    for (int j = 1; j <= n; j++) {
      if (union_set(cur.first, j)) {
        ans.push_back({cur.first, cur.second, cur.first, j});
        break;
      }
    }
  }
  if (ans.empty()) cout << 0, exit(0);
  cout << ans.size() << "\n";
  for (auto i : ans) {
    for (int j = 0; j < 4; j++) cout << i[j] << " "[j == 3];
    cout << "\n";
  }
}
