#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
std::ostream &operator<<(std::ostream &os, const std::pair<A, B> &p) {
  os << "{" << p.first << ", " << p.second << "}";
  return os;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
  bool fst = true;
  os << "{";
  for (auto t : v) {
    if (fst)
      fst = false;
    else
      os << ", ";
    os << t;
  }
  os << "}";
  return os;
}
const int N = 2e5 + 10;
int n;
vector<int> e[N];
int siz[N], mx[N];
vector<int> cen;
void getCen(int u, int p) {
  siz[u] = 1, mx[u] = 0;
  for (auto v : e[u])
    if (v != p) {
      getCen(v, u);
      siz[u] += siz[v];
      mx[u] = max(mx[u], siz[v]);
    }
  mx[u] = max(mx[u], n - siz[u]);
  if (!cen.size())
    cen = {u};
  else {
    int cur = mx[cen[0]];
    if (mx[u] < cur)
      cen = {u};
    else if (mx[u] == cur)
      cen.push_back(u);
  }
}
vector<int> nds;
int fa[N];
void dfs(int u, int p, int d) {
  if (d > 1) nds.push_back(u);
  fa[u] = p;
  for (auto v : e[u])
    if (v != p) dfs(v, u, d + 1);
}
vector<array<int, 3>> ans;
void solve(int u, int c) {
  nds.clear(), dfs(u, c, 0);
  reverse(nds.begin(), nds.end());
  int cur = u;
  for (auto v : nds) {
    ans.push_back({c, cur, v});
    ans.push_back({v, fa[v], u});
    cur = v;
  }
  ans.push_back({c, cur, u});
}
bool isCen[N];
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  getCen(1, 0);
  for (auto c : cen) isCen[c] = 1;
  {
    int c = cen[0];
    for (auto v : e[c])
      if (!isCen[v]) solve(v, c);
  }
  if (cen.size() > 1) {
    int c = cen[1];
    for (auto v : e[c])
      if (!isCen[v]) solve(v, c);
  }
  cout << ans.size() << '\n';
  for (auto t : ans) cout << t[0] << " " << t[1] << " " << t[2] << '\n';
  return 0;
}
