#include <bits/stdc++.h>
using namespace std;
const int MSIZE = 2e5;
int n;
int cnt[MSIZE];
vector<int> g[MSIZE];
int c1 = -1, c2 = -1;
void count(int v, int p = -1) {
  cnt[v]++;
  bool flag = true;
  for (int to : g[v])
    if (to != p) {
      count(to, v);
      if (cnt[to] * 2 > n) flag = false;
      cnt[v] += cnt[to];
    }
  if ((n - cnt[v]) * 2 > n) flag = false;
  if (flag) {
    if (c1 == -1)
      c1 = v;
    else
      c2 = v;
  }
}
vector<pair<int, int> > out;
void dfs_out(int v, int p) {
  for (int to : g[v])
    if (to != p) dfs_out(to, v);
  out.push_back({v, p});
}
vector<pair<int, pair<int, int> > > output;
void get_ans(int v, int p) {
  out.clear();
  dfs_out(v, p);
  out.pop_back();
  int cur = v;
  for (pair<int, int> a : out) {
    output.push_back({p, {cur, a.first}});
    output.push_back({a.first, {a.second, v}});
    cur = a.first;
  }
  output.push_back({p, {cur, v}});
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  count(0);
  for (int to : g[c1])
    if (to != c2) get_ans(to, c1);
  if (c2 != -1)
    for (int to : g[c2])
      if (to != c1) get_ans(to, c2);
  cout << output.size() << '\n';
  for (int i = 0; i < output.size(); ++i)
    cout << output[i].first + 1 << " " << output[i].second.first + 1 << " "
         << output[i].second.second + 1 << '\n';
  return 0;
}
