#include <bits/stdc++.h>
using namespace std;
int road[1010], pairs[1010][2];
int main() {
  int N, x, y, keep = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) road[i] = i;
  for (int i = 1; i < N; i++) {
    cin >> x >> y;
    if (road[x] == road[y]) {
      pairs[keep][0] = x;
      pairs[keep][1] = y;
      keep++;
    } else {
      int temp = road[y];
      for (int j = 1; j <= N; j++) {
        if (road[j] == temp) road[j] = road[x];
      }
    }
  }
  cout << keep << "\n";
  for (int i = 0; i < keep; i++) {
    int temp = 0;
    cout << pairs[i][0] << " " << pairs[i][1] << " " << road[1] << " ";
    for (int j = 1; j <= N; j++) {
      if (road[j] != road[1]) {
        cout << road[j] << "\n";
        temp = road[j];
        break;
      }
    }
    for (int j = 1; j <= N; j++) {
      if (road[j] == temp) road[j] = road[1];
    }
  }
}
