#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
int n;
vector<int> g[N], c;
int sz[N];
vector<array<int, 3>> a;
vector<pair<int, int>> d;
bool u[N];
void go(int v) {
  sz[v] = 1;
  int m = 0;
  for (int to : g[v])
    if (sz[to] == 0) {
      go(to);
      sz[v] += sz[to];
      m = max(m, sz[to]);
    }
  m = max(m, n - sz[v]);
  if (m * 2 <= n) c.push_back(v);
}
void og(int v, int c, int par = -1) {
  for (int to : g[v])
    if (!u[to] && to != par) og(to, c, v);
  if (par != -1 && par != c) d.emplace_back(v, par);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  go(0);
  for (int center : c) u[center] = true;
  for (int center : c) {
    for (int v : g[center]) {
      if (u[v]) continue;
      d.clear();
      og(v, v);
      if (d.size() == 0) continue;
      for (size_t i = 0; i < d.size(); ++i)
        if (d[i].second != -1 && d[i].second != v) {
          a.push_back({{center, i == 0 ? v : d[i - 1].first, d[i].first}});
          a.push_back({{d[i].first, d[i].second, v}});
        }
      a.push_back({{center, d.back().first, v}});
    }
  }
  printf("%d\n", (int)a.size());
  for (auto& x : a) printf("%d %d %d\n", x[0] + 1, x[1] + 1, x[2] + 1);
  return 0;
}
