#include <bits/stdc++.h>
using namespace std;
long long powerr(long long base, long long exp) {
  base %= 1000000007;
  long long result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % 1000000007;
    base = (base * base) % 1000000007;
    exp >>= 1;
  }
  return result;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
const int N = 1010;
set<int> seet;
int parent[N];
vector<pair<int, int> > red;
void init() {
  for (int i = 1; i < N; ++i) parent[i] = i;
}
int getparent(int u) {
  return (u == parent[u]) ? u : parent[u] = getparent(parent[u]);
}
void link(int u, int v) {
  int a = getparent(u);
  int b = getparent(v);
  if (a == b) {
    red.push_back({u, v});
    return;
  }
  parent[b] = a;
}
int main() {
  init();
  int n, u, v;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    scanf("%d", &u);
    scanf("%d", &v);
    link(u, v);
  }
  for (int i = 1; i <= n; ++i) seet.insert(getparent(i));
  printf("%d\n", red.size());
  for (int i = 0; i < red.size(); ++i) {
    auto it = seet.begin();
    auto it2 = it;
    int temp = *(it);
    ++it;
    int temp2 = *(it);
    printf("%d %d %d %d\n", red[i].first, red[i].second, temp, temp2);
    seet.erase(it2);
  }
}
