#include <bits/stdc++.h>
long long Pw(long long a, long long b, long long p) {
  long long v = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1) v = v * a % p;
  return v;
}
using namespace std;
int n, m, i, x, y, XX, YY, ST, ED, nv, sz[222222], mv[222222];
vector<int> V[222222], ZX;
vector<pair<int, pair<int, int> > > Q;
void dsz(int x, int fa) {
  sz[x] = 1;
  for (int y : V[x])
    if (y != fa) dsz(y, x), sz[x] += sz[y], mv[x] = max(mv[x], sz[y]);
}
void dfs(int x, int fa) {
  for (int y : V[x])
    if (y != fa) {
      dfs(y, x);
      if (ED != x) {
        Q.push_back(make_pair(ST, make_pair(nv, y)));
        Q.push_back(make_pair(y, make_pair(x, ED)));
        nv = y;
      }
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++)
    scanf("%d", &x), scanf("%d", &y), V[x].push_back(y), V[y].push_back(x);
  dsz(1, 0);
  for (int i = 1; i <= n; i++) {
    mv[i] = max(mv[i], n - sz[i]);
    if (mv[i] <= n / 2) ZX.push_back(i);
  }
  XX = ZX[0];
  if (ZX.size() == 2) YY = ZX[1];
  for (int x : ZX) {
    ST = x;
    for (int y : V[x])
      if (y != XX && y != YY) {
        nv = ED = y;
        dfs(y, x);
        Q.push_back(make_pair(x, make_pair(nv, y)));
      }
  }
  printf("%d\n", Q.size());
  for (int i = 0; i < Q.size(); i++)
    printf("%d %d %d\n", Q[i].first, Q[i].second.first, Q[i].second.second);
}
