#include <bits/stdc++.h>
using namespace std;
inline int Read() {
  int x = 0, f = 1, c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const int MAXN = 200005;
int par[MAXN], siz[MAXN], st[MAXN], dep[MAXN], tp, n;
vector<int> adj[MAXN], c[MAXN], r;
vector<pair<int, pair<int, int>>> ans;
inline void Dfs(int x, int p) {
  bool f = 1;
  siz[x] = 1;
  for (auto y : adj[x])
    if (y ^ p) {
      Dfs(y, x), siz[x] += siz[y];
      if (siz[y] > n >> 1) f = 0;
    }
  if (n - siz[x] > n >> 1) f = 0;
  if (f) r.push_back(x);
}
inline void Dfs2(int x, int p) {
  par[st[tp++] = x] = p;
  if (dep[x] >= 3) c[st[1]].push_back(x);
  for (auto y : adj[x])
    if (y ^ p) dep[y] = dep[x] + 1, Dfs2(y, x);
  tp--;
}
int main() {
  n = Read();
  for (int i = 1, x, y; i < n; i++)
    x = Read(), y = Read(), adj[x].push_back(y), adj[y].push_back(x);
  Dfs(1, 0);
  if (r.size() == 1)
    Dfs2(r[0], 0);
  else
    Dfs2(r[0], r[1]), Dfs2(r[1], r[0]);
  for (int i = 1; i <= n; i++)
    if (c[i].size()) {
      int cur = i;
      for (auto x : c[i])
        ans.push_back(make_pair(par[i], make_pair(cur, x))),
            ans.push_back(make_pair(x, make_pair(par[x], i))), cur = x;
      ans.push_back(make_pair(par[i], make_pair(cur, i)));
    }
  printf("%d\n", ans.size());
  for (auto x : ans)
    printf("%d %d %d\n", x.first, x.second.first, x.second.second);
}
