#include <bits/stdc++.h>
using namespace std;
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 = 200000 + 5;
vector<int> V[MAXN], r, C[MAXN];
vector<pair<int, pair<int, int> > > res;
int n, st[MAXN], top, sz[MAXN], deep[MAXN], pre[MAXN];
void dfs(int u, int p) {
  sz[u] = 1;
  int flag = 1;
  for (auto v : V[u]) {
    if (v == p) continue;
    dfs(v, u);
    sz[u] += sz[v];
    if (sz[v] > n >> 1) flag = 0;
  }
  if (n - sz[u] > n >> 1) flag = 0;
  if (flag) r.push_back(u);
}
void dfs2(int u, int p) {
  pre[st[top++] = u] = p;
  if (deep[u] >= 3) C[st[1]].push_back(u);
  for (auto v : V[u]) {
    if (v == p) continue;
    deep[v] = deep[u] + 1;
    dfs2(v, u);
  }
  top--;
}
int main() {
  n = read();
  for (int i = 1, u, v; i < n; i++) {
    u = read(), v = read();
    V[u].push_back(v);
    V[v].push_back(u);
  }
  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]) {
        res.push_back(make_pair(pre[i], make_pair(cur, x))),
            res.push_back(make_pair(x, make_pair(pre[x], i))), cur = x;
      }
      res.push_back(make_pair(pre[i], make_pair(cur, i)));
    }
  }
  printf("%d\n", res.size());
  for (auto x : res) {
    printf("%d %d %d\n", x.first, x.second.first, x.second.second);
  }
  return 0;
}
