#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
long long N;
vector<long long> G[222222];
bool centroid[222222];
long long subtree_size[222222];
long long compute_subtree_size(long long v, long long p) {
  long long c = 1;
  for (auto u : G[v]) {
    if (u == p || centroid[u]) continue;
    c += compute_subtree_size(u, v);
  }
  subtree_size[v] = c;
  return c;
}
pair<long long, long long> search_centroid(long long v, long long p,
                                           long long t) {
  pair<long long, long long> res = {INT_MAX, -1};
  long long s = 1, m = 0;
  for (auto u : G[v]) {
    if (u == p || centroid[u]) continue;
    res = min(res, search_centroid(u, v, t));
    m = max(m, subtree_size[u]);
    s += subtree_size[u];
  }
  m = max(m, t - s);
  res = min(res, {m, v});
  return res;
}
vector<tuple<long long, long long, long long>> ans;
long long g;
long long s;
long long pre;
void dfs(long long v, long long p, long long d) {
  for (auto u : G[v]) {
    if (u == p) continue;
    dfs(u, v, d + 1);
  }
  if (d > 1) {
    ans.push_back(make_tuple(g, pre, v));
    ans.push_back(make_tuple(v, p, s));
    pre = v;
  }
}
signed main() {
  cin >> N;
  for (long long i = 0; i < (N - 1); i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  compute_subtree_size(0, -1);
  long long x = search_centroid(0, -1, N).second;
  compute_subtree_size(x, -1);
  long long y = -1;
  for (auto u : G[x]) {
    if (subtree_size[u] * 2 == N) {
      y = u;
    }
  }
  for (auto u : G[x]) {
    if (u == y) continue;
    g = x;
    pre = u;
    s = u;
    dfs(u, x, 0);
    if (pre != u) {
      ans.push_back(make_tuple(x, pre, u));
    }
  }
  if (y != -1) {
    for (auto u : G[y]) {
      if (u == x) continue;
      g = y;
      pre = u;
      s = u;
      dfs(u, y, 0);
      if (pre != u) {
        ans.push_back(make_tuple(y, pre, u));
      }
    }
  }
  printf("%lld\n", (long long)ans.size());
  for (long long i = 0; i < (ans.size()); i++)
    printf("%lld %lld %lld\n", get<0>(ans[i]) + 1, get<1>(ans[i]) + 1,
           get<2>(ans[i]) + 1);
  return 0;
}
