4
1 4
3 1
3 4
 5
4 1
4 3
5 3
2 4
 21
7 15
13 1
14 3
4 10
2 3
16 18
17 20
16 20
8 4
3 12
2 17
13 11
16 1
13 2
13 5
8 9
6 14
3 17
16 9
13 8
 3
3 1
3 2
 6
5 2
5 3
1 4
3 1
5 6
 60
17 34
46 22
50 44
46 33
41 21
31 33
48 6
38 19
35 60
2 24
49 29
7 53
34 1
19 55
32 1
31 42
27 28
4 53
6 50
21 34
1 10
12 36
54 8
16 13
51 43
45 51
54 20
13 53
34 33
49 33
51 11
59 34
15 5
59 28
30 39
13 30
58 4
34 14
3 9
19 34
4 18
26 48
56 54
3 43
57 25
3 41
35 3
48 44
19 13
54 1
23 31
59 47
5 1
46 40
6 26
20 25
37 5
17 24
20 52
 3
3 2
1 2
 39
6 13
15 39
10 35
31 28
4 21
12 39
3 7
3 13
6 1
5 14
36 28
12 15
18 38
30 29
19 34
36 16
20 22
8 13
38 32
26 39
21 37
1 7
15 27
12 26
8 3
6 14
29 2
25 23
32 21
5 16
32 25
6 8
13 10
23 30
34 37
29 33
28 14
36 5
 10
5 9
8 5
7 6
7 9
3 9
2 1
7 2
3 6
7 1

1
3 4 1 2  0
 3
13 2 1 7 3 17 1 19 13 8 1 21  0
 0
 2
48 44 1 6 6 26 1 12  0
 7
12 15 1 2 1 7 1 9 12 26 1 11 8 3 1 12 6 8 1 17 28 14 1 20 36 5 1 24  2
3 6 1 4 7 1 1 10 
#include <bits/stdc++.h>
template <typename T>
class AdjList {
 private:
  typename std::vector<std::forward_list<T>>::size_type numNodes = 0;
  std::vector<std::forward_list<T>> adjList;
  void print_forward_list(const std::forward_list<T>& elems) const;

 public:
  AdjList(typename std::vector<std::forward_list<T>>::size_type numNodes);
  typename std::vector<std::forward_list<T>>::size_type getNumNodes() const;
  void setNumNodes(
      typename std::vector<std::forward_list<T>>::size_type numNodes);
  void pushEdge(T const& from, T const& to);
  void popEdge(T const& from);
  void delEdge(T const& from, T const& to);
  void removeAdj(T const& from);
  void removeVertex(T const& from);
  typename std::forward_list<T>::const_iterator begin(T const& from) const;
  typename std::forward_list<T>::const_iterator end(T const& from) const;
  typename std::forward_list<T>& adjacent(T const& from);
  bool hasAdj(T const& from) const;
  void print() const;
};
template <typename T>
AdjList<T>::AdjList(
    typename std::vector<std::forward_list<T>>::size_type numNodes)
    : numNodes(numNodes), adjList(numNodes, std::forward_list<T>()) {}
template <typename T>
typename std::vector<std::forward_list<T>>::size_type AdjList<T>::getNumNodes()
    const {
  return numNodes;
}
template <typename T>
void AdjList<T>::setNumNodes(
    typename std::vector<std::forward_list<T>>::size_type numNodes) {
  this->numNodes = numNodes;
}
template <typename T>
void AdjList<T>::pushEdge(T const& from, T const& to) {
  adjList[from].push_front(to);
}
template <typename T>
void AdjList<T>::popEdge(T const& from) {
  adjList[from].pop_front();
}
template <typename T>
void AdjList<T>::delEdge(T const& from, T const& to) {
  for (auto& elem : adjList[from])
    if (elem == to) adjList[from].erase(elem);
}
template <typename T>
typename std::forward_list<T>::const_iterator AdjList<T>::begin(
    T const& from) const {
  return adjList[from].cbegin();
}
template <typename T>
typename std::forward_list<T>::const_iterator AdjList<T>::end(
    T const& from) const {
  return adjList[from].cend();
}
template <typename T>
typename std::forward_list<T>& AdjList<T>::adjacent(T const& from) {
  return adjList[from];
}
template <typename T>
bool AdjList<T>::hasAdj(T const& from) const {
  return !(adjList[from].empty());
}
template <typename T>
void AdjList<T>::removeAdj(T const& from) {
  adjList[from] = std::forward_list<T>();
}
template <typename T>
void AdjList<T>::removeVertex(T const& from) {
  adjList.erase(adjList.begin() + from);
  for (auto& llist : adjList) {
    llist.remove_if([from](T const& to) { return to == from; });
  }
}
template <typename T>
void AdjList<T>::print_forward_list(const std::forward_list<T>& elems) const {
  if (!elems.empty()) {
    typename std::forward_list<T>::const_iterator iter, end = elems.end();
    for (iter = elems.begin(); std::next(iter) != end; ++iter)
      std::cout << *iter << ", " << std::flush;
    std::cout << *iter;
  }
}
template <typename T>
void AdjList<T>::print() const {
  auto begin = adjList.begin(), end = adjList.end();
  for (auto iter = begin; iter != end; ++iter) {
    std::cout << iter - begin << ": " << std::flush;
    print_forward_list(*iter);
    std::cout << std::endl;
  }
}
using namespace std;
using namespace std;
void dfs(int from, vector<bool>& visited, AdjList<int>& adjList);
void print_vector(const std::vector<int>& elems) {
  for (int i = 0; i < 3; i++) std::cout << elems[i] + 1 << ' ' << std::flush;
  std::cout << elems[3] + 1 << std::endl;
}
vector<int> edge(2);
stack<vector<int>> edges;
int main() {
  int cities, roads, from, to;
  cin >> cities;
  AdjList<int> adjList(cities);
  roads = cities - 1;
  for (int i = 0; i < roads; i++) {
    cin >> from >> to;
    from--;
    to--;
    adjList.pushEdge(from, to);
    adjList.pushEdge(to, from);
  }
  vector<bool> visited(cities, false);
  vector<vector<int>> roadChanges;
  vector<int> changes;
  for (from = 0; from < cities; from++) {
    if (!visited[from]) {
      if (from != 0) {
        changes.push_back(from);
        roadChanges.push_back(changes);
      }
      changes.resize(0);
      dfs(from, visited, adjList);
      edge = edges.top();
      edges.pop();
      changes.push_back(edge[0]);
      changes.push_back(edge[1]);
      changes.push_back(edge[0]);
    }
  }
  cout << roadChanges.size() << endl;
  for (auto& change : roadChanges) print_vector(change);
  return 0;
}
void dfs(int from, vector<bool>& visited, AdjList<int>& adjList) {
  if (!visited[from]) {
    visited[from] = true;
    int to;
    auto adjVerts = adjList.adjacent(from);
    for (auto iter = adjVerts.begin(), end = adjVerts.end(); iter != end;
         ++iter) {
      to = *iter;
      edge[0] = from;
      edge[1] = to;
      edges.push(edge);
      dfs(to, visited, adjList);
    }
  }
}
