#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 99;
int n, u, v, t, last, sub[N], par[N], deg[N];
queue<int> q;
vector<int> cent, g[N];
vector<pair<int, pair<int, int> > > ans;
void read() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    ;
    g[u].push_back(v);
    g[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
}
void dfs(int x, int par) {
  bool is_cent = 1;
  sub[x] = 1;
  for (int i = 0; i < g[x].size(); i++)
    if (g[x][i] != par) {
      dfs(g[x][i], x);
      sub[x] += sub[g[x][i]];
      is_cent &= (sub[g[x][i]] <= n / 2);
    }
  is_cent &= (n - sub[x] <= n / 2);
  if (is_cent) cent.push_back(x);
}
void dfs1(int x, int rt) {
  if (x != rt && par[x] != rt && g[x].size() == 1) q.push(x);
  for (int i = 0; i < g[x].size(); i++)
    if (g[x][i] != par[x]) {
      par[g[x][i]] = x;
      dfs1(g[x][i], rt);
    }
}
void change(int u, int rt, int cent) {
  ans.push_back(make_pair(cent, make_pair(last, u)));
  ans.push_back(make_pair(u, make_pair(par[u], rt)));
  deg[par[u]]--;
  last = u;
  if (par[par[u]] != rt && deg[par[u]] == 1) q.push(par[u]);
}
void solve(int rt, int cent) {
  par[rt] = cent;
  dfs1(rt, rt);
  last = rt;
  while (q.size()) {
    int u = q.front();
    q.pop();
    change(u, rt, cent);
  }
  ans.push_back(make_pair(cent, make_pair(last, rt)));
}
void do_it() {
  for (int k = 0; k < int(cent.size()); k++) {
    u = cent[k];
    for (int i = 0; i < g[u].size(); i++)
      if (g[u][i] != cent[0] && g[u][i] != cent[cent.size() - 1])
        solve(g[u][i], cent[k]);
  }
  cout << int(ans.size()) << '\n';
  for (int i = 0; i < int(ans.size()); i++)
    cout << ans[i].first << " " << ans[i].second.first << " "
         << ans[i].second.second << '\n';
}
void find_centroids() { dfs(1, 0); }
int main() {
  read();
  find_centroids();
  do_it();
}
