#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && (c != '-')) c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
const int N = 2e5 + 10;
int n;
vector<int> e[N];
vector<pair<int, pair<int, int>>> ans;
int rt, rt2, siz[N], mx[N];
inline void dfs(int u, int fa) {
  siz[u] = 1;
  for (auto v : e[u])
    if (v != fa) {
      dfs(v, u), siz[u] += siz[v];
      mx[u] = max(mx[u], siz[v]);
    }
  mx[u] = max(mx[u], n - siz[u]);
  if (mx[u] < mx[rt])
    rt = u, rt2 = 0;
  else if (mx[u] == mx[rt])
    rt2 = u;
}
int main() {
  n = read();
  for (register int i = (1); i < (n); i++) {
    int x = read(), y = read();
    e[x].push_back(y), e[y].push_back(x);
  }
  if (n <= 3) return puts("0"), 0;
  mx[0] = n, dfs(1, 0);
  int now;
  function<void(int, int, int, int, int)> dfs = [&](int u, int fa, int rt,
                                                    int rt1, int rt2) {
    for (auto v : e[u])
      if (v != fa) dfs(v, u, rt, rt1, rt2);
    if (u != rt) {
      ans.push_back({rt2, {now, u}});
      ans.push_back({u, {fa, rt1}});
      now = u;
    }
  };
  if (rt2) {
    for (auto v : e[rt])
      if (v != rt2) {
        now = v;
        for (auto v2 : e[v])
          if (v2 != rt) {
            dfs(v2, v, v2, v, rt);
          }
        ans.push_back({rt, {now, v}});
      }
    for (auto v : e[rt2])
      if (v != rt) {
        now = v;
        for (auto v2 : e[v])
          if (v2 != rt2) {
            dfs(v2, v, v2, v, rt2);
          }
        ans.push_back({rt2, {now, v}});
      }
  } else {
    for (auto v : e[rt]) {
      now = v;
      for (auto v2 : e[v])
        if (v2 != rt) {
          dfs(v2, v, v2, v, rt);
        }
      ans.push_back({rt, {now, v}});
    }
  }
  printf("%d\n", ((int)(ans).size()));
  for (auto i : ans)
    printf("%d %d %d\n", i.first, i.second.first, i.second.second);
}
