#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
vector<pair<int, pair<int, int> > > ans;
long long n, s[MAXN], id1 = -1, id2 = -1, deg[MAXN], sum[MAXN];
vector<int> g[MAXN];
bool vis[MAXN];
void add(int a, int b, int c) { ans.push_back({a, {b, c}}); }
void dfscent(int v, int f = -1) {
  s[v] = 1;
  bool b = 1;
  for (int u : g[v])
    if (u != f) {
      dfscent(u, v);
      s[v] += s[u];
      if (s[u] > n / 2) b = 0;
    }
  if (n - s[v] > n / 2) b = 0;
  if (b) {
    if (id1 == -1)
      id1 = v;
    else
      id2 = v;
  }
}
void go(int u, int v) {
  queue<int> q;
  vector<int> t;
  q.push(u);
  t.push_back(u);
  vis[u] = 1;
  vis[v] = 1;
  while (!q.empty()) {
    int y = q.front();
    q.pop();
    for (int z : g[y])
      if (!vis[z]) {
        vis[z] = 1;
        t.push_back(z);
        q.push(z);
      }
  }
  if (t.size() == 1) return;
  for (int z : t) {
    deg[z] = g[z].size();
    for (int y : g[z]) sum[z] += y;
  }
  int a = v, b = u;
  for (int z : t) {
    if (deg[z] == 1) q.push(z);
  }
  t.clear();
  t.push_back(v);
  while (!q.empty()) {
    int z = q.front();
    q.pop();
    t.push_back(z);
    if (z == b) break;
    add(a, b, z);
    deg[b]--;
    sum[b] -= a;
    if (deg[b] == 1) q.push(b);
    a = z, b = sum[z];
  }
  int z = t.back();
  for (int i = (int)t.size() - 3; i >= 0; --i) add(t[i], t[i + 1], z);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfscent(0);
  if (id2 == -1) {
    for (int u : g[id1]) go(u, id1);
  } else {
    for (int u : g[id1])
      if (u != id2) go(u, id1);
    for (int u : g[id2])
      if (u != id1) go(u, id2);
  }
  cout << ans.size() << "\n";
  for (auto it : ans)
    cout << it.first + 1 << ' ' << it.second.first + 1 << ' '
         << it.second.second + 1 << "\n";
}
