#include <bits/stdc++.h>
using namespace std;
int n, centroid, centroidDad, sz[200005], dad[200005];
vector<int> G[200005];
vector<tuple<int, int, int> > sol;
void DFS(int u, int p) {
  sz[u] = 1;
  dad[u] = p;
  for (auto x : G[u]) {
    if (x != p) {
      DFS(x, u);
      sz[u] += sz[x];
    }
  }
}
int findCentroid() {
  DFS(1, 0);
  for (int i = 1; i <= n; ++i) {
    bool can = 1;
    int totSz = 1;
    for (auto x : G[i]) {
      if (x != dad[i]) {
        if (sz[x] > n / 2) {
          can = 0;
          break;
        }
        totSz += sz[x];
      }
    }
    if (n - totSz > n / 2) can = 0;
    if (can) return i;
  }
  assert(0);
  return -1;
}
void make_op(int u, int dad, int new_dad) {
  sol.push_back(make_tuple(u, dad, new_dad));
}
void DFS2(int u, int p, int root) {
  int centroid = dad[root];
  if (dad[u] != root && u != root) {
    make_op(centroid, centroidDad, u);
    make_op(u, dad[u], root);
    centroidDad = u;
  }
  for (auto x : G[u]) {
    if (x != p) {
      DFS2(x, u, root);
    }
  }
}
void process(int u) {
  int centroid = dad[u];
  centroidDad = u;
  DFS2(u, centroid, u);
  make_op(centroid, centroidDad, u);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  centroid = findCentroid();
  DFS(centroid, 0);
  for (auto x : G[centroid]) {
    if (sz[x] < n - sz[x]) {
      process(x);
    } else {
      for (auto y : G[x]) {
        if (y != centroid) {
          process(y);
        }
      }
    }
  }
  cout << sol.size() << "\n";
  for (auto x : sol) {
    cout << get<0>(x) << " " << get<1>(x) << " " << get<2>(x) << "\n";
  }
  return 0;
}
