#include <bits/stdc++.h>
using namespace std;
int n, sizeAt[200000];
unordered_set<int> connections[200000];
vector<int> centroids;
bool isCentroid[200000];
vector<tuple<int, int, int>> transformations;
void dfsSize(int node, int par) {
  sizeAt[node] = 1;
  for (const int next : connections[node]) {
    if (next == par) continue;
    dfsSize(next, node);
    sizeAt[node] += sizeAt[next];
  }
}
void findCentroids(int node, int par) {
  for (const int next : connections[node]) {
    if (next != par && 2 * sizeAt[next] > n) {
      findCentroids(next, node);
      return;
    }
    if (next != par && 2 * sizeAt[next] == n) findCentroids(next, node);
  }
  isCentroid[node] = true;
  centroids.push_back(node);
}
void trans(int x, int y, int z) {
  if (y == z) return;
  connections[x].erase(y);
  connections[y].erase(x);
  connections[x].insert(z);
  connections[z].insert(x);
  transformations.push_back(make_tuple(x, y, z));
}
pair<int, int> straighten(int node, int par) {
  int head = node, tail = node;
  vector<int> toProcess;
  for (const int next : connections[node])
    if (next != par) toProcess.push_back(next);
  for (const int next : toProcess) {
    pair<int, int> ht = straighten(next, node);
    if (head == node) {
      trans(par, node, ht.second);
      head = ht.second;
      tail = ht.first;
    } else {
      trans(tail, node, ht.second);
      tail = ht.first;
    }
  }
  tail = node;
  return make_pair(head, tail);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < (n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    connections[a].insert(b);
    connections[b].insert(a);
  }
  dfsSize(0, -1);
  findCentroids(0, -1);
  for (const int centroid : centroids) {
    vector<int> childrenToProcess;
    for (const int child : connections[centroid]) {
      if (isCentroid[child]) continue;
      childrenToProcess.push_back(child);
    }
    for (const int child : childrenToProcess) {
      pair<int, int> ht = straighten(child, centroid);
      int curr = ht.second;
      int last = -1;
      while (1) {
        if (curr != ht.second) trans(curr, last, ht.second);
        if (curr == centroid) break;
        for (const int next : connections[curr]) {
          if (next != ht.second) {
            last = curr;
            curr = next;
            break;
          }
        }
      }
    }
  }
  cout << transformations.size() << "\n";
  for (const tuple<int, int, int> t : transformations)
    cout << get<0>(t) + 1 << " " << get<1>(t) + 1 << " " << get<2>(t) + 1
         << "\n";
  return 0;
}
