#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n, parent[maxn];
int find_set(int v) {
  if (parent[v] == v)
    return v;
  else
    find_set(parent[v]);
}
struct t {
  int x;
  int y;
};
t close[maxn];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) parent[i] = i;
  int k = 0;
  for (int i = 0; i < n - 1; i++) {
    int a, b, x, y;
    cin >> a >> b;
    a--;
    b--;
    x = find_set(a);
    y = find_set(b);
    if (x == y) {
      close[k].x = a;
      close[k].y = b;
      k++;
    } else
      parent[x] = y;
  }
  if (k == 0) {
    cout << 0;
    return 0;
  }
  int x = find_set(0);
  cout << k << endl;
  k--;
  for (int i = 1; i < n; i++) {
    int y = find_set(i);
    if (x != y) {
      parent[y] = parent[x];
      cout << close[k].x + 1 << ' ' << close[k].y + 1 << ' ' << 1 << ' '
           << i + 1 << endl;
      k--;
    }
    if (k == -1) return 0;
  }
  return 0;
}
