#include <bits/stdc++.h>
using namespace std;
const int maxn = 202020;
vector<int> tr[maxn];
int sz[maxn], par[maxn], dep[maxn];
void dfs(int cur, int pr) {
  par[cur] = pr;
  sz[cur] = 1;
  for (int nxt : tr[cur]) {
    if (nxt == pr) continue;
    dep[nxt] = dep[cur] + 1;
    dfs(nxt, cur);
    sz[cur] += sz[nxt];
  }
}
vector<tuple<int, int, int> > o;
int sons[maxn];
queue<int> q;
void push_build(int cur, int pr) {
  par[cur] = pr;
  for (int nxt : tr[cur]) {
    if (nxt == pr) continue;
    dep[nxt] = dep[cur] + 1;
    push_build(nxt, cur);
    sons[cur]++;
  }
  if (sons[cur] == 0) q.push(cur);
}
void build(int cur, int pr) {
  for (int nxt : tr[cur]) {
    if (nxt == pr) continue;
    assert(q.empty());
    dep[nxt] = 1;
    push_build(nxt, cur);
    int bad = nxt;
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      if (dep[now] < 3) continue;
      o.push_back(make_tuple(cur, bad, now));
      o.push_back(make_tuple(now, par[now], nxt));
      bad = now;
      if (--sons[par[now]] == 0) q.push(par[now]);
    }
    if (bad != nxt) {
      o.push_back(make_tuple(cur, bad, nxt));
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int e = 0; e < n - 1; e++) {
    int u, v;
    scanf("%d %d", &u, &v);
    tr[u].push_back(v);
    tr[v].push_back(u);
  }
  dfs(1, 0);
  vector<int> cen;
  for (int e = 1; e <= n; e++) {
    int mx = n - sz[e];
    for (int nxt : tr[e]) {
      if (nxt == par[e]) continue;
      mx = max(mx, sz[nxt]);
    }
    if (mx <= n / 2) cen.push_back(e);
  }
  if (cen.size() == 1) {
    build(cen[0], 0);
  } else {
    build(cen[0], cen[1]);
    build(cen[1], cen[0]);
  }
  printf("%d\n", (int)o.size());
  for (auto e : o) {
    int u, v, w;
    tie(u, v, w) = e;
    printf("%d %d %d\n", u, v, w);
  }
  return 0;
}
