#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 10;
vector<long long> vertex[MAXN];
vector<pair<long long, pair<long long, long long> > > res;
long long check[MAXN];
long long subtree[MAXN];
bool main_check[MAXN];
long long t = 1, last = 0;
void set_subtree(long long v) {
  check[v] = t;
  subtree[v] = 1;
  for (long long i = 0; i < vertex[v].size(); i++) {
    if (check[vertex[v][i]] != t) {
      set_subtree(vertex[v][i]);
      subtree[v] += subtree[vertex[v][i]];
    }
  }
}
pair<long long, long long> get_centroid(long long v, long long root) {
  check[v] = t;
  for (long long i = 0; i < vertex[v].size(); i++) {
    if (check[vertex[v][i]] != t && 2 * subtree[vertex[v][i]] > subtree[root]) {
      return get_centroid(vertex[v][i], root);
    }
    if (check[vertex[v][i]] != t &&
        2 * subtree[vertex[v][i]] == subtree[root]) {
      return make_pair(v, get_centroid(vertex[v][i], root).first);
    }
  }
  return make_pair(v, (long long)(0));
}
void dfs(long long v, long long par, long long u, long long w) {
  main_check[v] = true;
  if (par != w) {
    res.push_back(make_pair(w, make_pair(last, v)));
    res.push_back(make_pair(v, make_pair(par, u)));
    last = v;
  }
  for (long long i = 0; i < vertex[v].size(); i++) {
    if (!main_check[vertex[v][i]]) {
      dfs(vertex[v][i], v, u, w);
    }
  }
}
void solve(long long v) {
  main_check[v] = true;
  for (long long i = 0; i < vertex[v].size(); i++) {
    if (!main_check[vertex[v][i]]) {
      last = vertex[v][i];
      dfs(vertex[v][i], v, vertex[v][i], v);
      res.push_back(make_pair(v, make_pair(last, vertex[v][i])));
    }
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < (n - 1); i++) {
    long long v, u;
    cin >> v >> u;
    vertex[v].push_back(u);
    vertex[u].push_back(v);
  }
  t++;
  set_subtree(1);
  t++;
  pair<long long, long long> d = get_centroid(1, 1);
  if (d.second == 0) {
    solve(d.first);
  } else {
    main_check[d.second] = true;
    solve(d.first);
    solve(d.second);
  }
  cout << (long long)(res.size()) << endl;
  for (long long i = 0; i < res.size(); i++) {
    cout << res[i].first << " " << res[i].second.first << " "
         << res[i].second.second << endl;
  }
}
