#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << "," << p.second << "}";
  return os;
}
const int N = 3e5 + 5;
const int oo = 1e9 + 7;
set<int> g[N];
int sz[N];
vector<tuple<int, int, int> > ans;
int dfs_sz(int u, int p) {
  sz[u] = 1;
  for (int v : g[u])
    if (v != p) sz[u] += dfs_sz(v, u);
  return sz[u];
}
int find_centroid(int u, int p, int size) {
  for (int v : g[u])
    if (v != p and sz[v] > size / 2) return find_centroid(v, u, size);
  return u;
}
int make_centroid_tree(int u) {
  int size = dfs_sz(u, u);
  u = find_centroid(u, u, size);
  return u;
}
int find_leaf(int u, int p = -1) {
  for (int v : g[u])
    if (v != p) return find_leaf(v);
  return u;
}
vector<int> chain;
void make_chain(int u, int p, int &uu, int &vv) {
  for (int v : g[u])
    if (v != p) make_chain(v, u, uu, vv);
  chain.push_back(u);
  if (u != vv) ans.push_back(make_tuple(uu, vv, u));
  uu = u, vv = p;
}
void make_star(int u) {
  int n = chain.size();
  for (int i = n - 4; i >= 0; i--) {
    ans.push_back(make_tuple(chain[i], chain[i + 1], chain[n - 2]));
  }
  if (n >= 3) ans.push_back(make_tuple(u, chain.front(), chain[n - 2]));
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].insert(v);
    g[v].insert(u);
  }
  int centroid = make_centroid_tree(1);
  for (int v : g[centroid]) {
    g[v].erase(centroid);
    int size = dfs_sz(v, centroid);
    if (n - size <= size) {
      int centroid = v;
      for (int v : g[centroid]) {
        g[v].erase(centroid);
        chain.clear();
        int uu = centroid, vv = v;
        make_chain(v, centroid, uu, vv);
        make_star(centroid);
      }
    } else {
      chain.clear();
      int uu = centroid, vv = v;
      make_chain(v, centroid, uu, vv);
      make_star(centroid);
    }
  }
  cout << ans.size() << "\n";
  for (auto i : ans) {
    cout << get<0>(i) << " ";
    cout << get<1>(i) << " ";
    cout << get<2>(i) << "\n";
  }
}
