#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 100000 + 5;
vector<int> g[maxn];
const int inf = 0x3f3f3f3f;
void addedge(int from, int to) {
  g[from].push_back(to);
  g[to].push_back(from);
}
int n;
int siz[maxn];
void predfs(int v, int fa) {
  siz[v] = 1;
  for (int i = 0; i < (int)g[v].size(); i++) {
    int u = g[v][i];
    if (u != fa) {
      predfs(u, v);
      siz[v] += siz[u];
    }
  }
}
int Findcent(int v, int fa) {
  for (int i = 0; i < (int)g[v].size(); i++) {
    int u = g[v][i];
    if (u != fa && siz[u] > n / 2) return Findcent(u, v);
  }
  return v;
}
vector<pair<int, pair<int, int> > > Ans;
vector<pair<int, int> > topo;
void dfs(int v, int fa) {
  for (int i = 0; i < (int)g[v].size(); i++) {
    int u = g[v][i];
    if (u != fa) {
      dfs(u, v);
    }
  }
  topo.push_back(make_pair(v, fa));
}
void getans(int v, int fa) {
  topo.clear();
  dfs(v, fa);
  topo.pop_back();
  int iter = v;
  for (int i = 0; i < (int)topo.size(); i++) {
    pair<int, int> now = topo[i];
    Ans.push_back(make_pair(fa, make_pair(iter, now.first)));
    Ans.push_back(make_pair(now.first, make_pair(now.second, v)));
    iter = now.first;
  }
  Ans.push_back(make_pair(fa, make_pair(iter, v)));
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int from, to;
    scanf("%d%d", &from, &to);
    addedge(from, to);
  }
  predfs(1, -1);
  int Cent = Findcent(1, -1);
  int Cent2 = 0;
  for (int i = 0; i < (int)g[Cent].size(); i++) {
    int u = g[Cent][i];
    if (siz[u] * 2 == n) Cent2 = u;
  }
  for (int i = 0; i < (int)g[Cent].size(); i++) {
    int u = g[Cent][i];
    if (u != Cent2) getans(u, Cent);
  }
  if (Cent2 != 0) {
    for (int i = 0; i < (int)g[Cent2].size(); i++) {
      int u = g[Cent2][i];
      if (u != Cent) getans(u, Cent2);
    }
  }
  printf("%d\n", Ans.size());
  for (int i = 0; i < (int)Ans.size(); i++) {
    printf("%d %d %d\n", Ans[i].first, Ans[i].second.first,
           Ans[i].second.second);
  }
  return 0;
}
