#include <bits/stdc++.h>
using namespace std;
int cnt[200001], n, par;
vector<int> adj[200001];
vector<pair<int, int> > v;
void count(int h, int p) {
  cnt[h]++;
  for (auto it : adj[h])
    if (it ^ p) {
      count(it, h);
      cnt[h] += cnt[it];
    }
}
int ct(int h, int p) {
  for (auto it : adj[h])
    if (it ^ p) {
      if (cnt[it] > n / 2) return ct(it, h);
    }
  par = p;
  return h;
}
vector<pair<int, pair<int, int> > > res;
void dfs(int h, int p) {
  for (auto it : adj[h])
    if (it ^ p) {
      dfs(it, h);
    }
  v.push_back({h, p});
}
void f(int h, int p) {
  v.clear();
  dfs(h, p);
  v.pop_back();
  int t = h;
  for (auto it : v) {
    res.push_back({p, {t, it.first}});
    res.push_back({it.first, {it.second, h}});
    t = it.first;
  }
  res.push_back({p, {t, h}});
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  count(1, 0);
  int cen = ct(1, 0);
  int cen2 = 0;
  for (auto it : adj[cen])
    if (par ^ it && 2 * cnt[it] == n) cen2 = it;
  for (auto it : adj[cen])
    if (it ^ cen2) f(it, cen);
  for (auto it : adj[cen2])
    if (it ^ cen) f(it, cen2);
  printf("%d\n", res.size());
  for (auto it : res)
    printf("%d %d %d\n", it.first, it.second.first, it.second.second);
  return 0;
}
