#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
;
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long normalize(long long x, long long mod) {
  x %= mod;
  if (x < 0) x += mod;
  return x;
}
long long dx[4] = {0, 0, 1, -1};
long long dy[4] = {1, -1, 0, 0};
const long long mod = 1000 * 1000 * 1000 + 7;
const long long inf = 1e18 + 5;
long long powm(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
const long long N = 1e5 + 5;
long long n;
long long parent[1005], rank1[1005];
vector<pair<long long, long long> > rem;
void make_set(long long v) {
  parent[v] = v;
  rank1[v] = 0;
}
long long find_set(long long v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void union_sets(long long a, long long b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (rank1[a] < rank1[b]) swap(a, b);
    parent[b] = a;
    if (rank1[a] == rank1[b]) rank1[a]++;
  }
}
void solve() {
  cin >> n;
  for (long long i = (1); i < (n + 1); ++i) make_set(i);
  for (long long i = (1); i < (n); ++i) {
    long long u, v;
    cin >> u >> v;
    if (find_set(u) == find_set(v))
      rem.push_back({u, v});
    else
      union_sets(u, v);
  }
  vector<long long> tmp;
  for (long long i = (1); i < (n + 1); ++i) {
    if (find_set(i) == i) tmp.push_back(i);
  }
  cout << ((long long)tmp.size()) - 1 << "\n";
  for (long long i = (0); i < (((long long)tmp.size()) - 1); ++i)
    cout << rem[i].first << " " << rem[i].second << " " << tmp[i] << " "
         << tmp[i + 1] << "\n";
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
