#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 100 * 1000 + 2;
int n, cnt[N], mx[N], par[N], x, y = -1;
vector<int> adj[N], vec, ans[3];
void dfs1(int u, int p) {
  cnt[u] = 1;
  for (int v : adj[u])
    if (v != p) {
      dfs1(v, u);
      cnt[u] += cnt[v];
      if (mx[u] == -1 || cnt[mx[u]] < cnt[v]) mx[u] = v;
    }
}
void findCentroid() {
  mx[0] = -1;
  dfs1(0, -1);
  while (mx[x] != -1 && cnt[mx[x]] * 2 > n) x = mx[x];
  if (cnt[mx[x]] * 2 == n) y = mx[x];
}
void dfs2(int u, int p) {
  for (int v : adj[u])
    if (v != p) {
      vec.push_back(v);
      par[v] = u;
      dfs2(v, u);
    }
}
void add(int a, int b, int c) {
  ans[0].push_back(a + 1);
  ans[1].push_back(b + 1);
  ans[2].push_back(c + 1);
}
void solve(int root) {
  if (root != -1)
    for (int i = 0; i < adj[root].size(); i++) {
      int u = adj[root][i];
      if (u != x && u != y) {
        vec.clear();
        dfs2(u, root);
        for (int v : vec) {
          add(root, u, v);
          add(v, par[v], adj[root][i]);
          u = v;
        }
        add(root, u, adj[root][i]);
      }
    }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1, u, v; i < n; i++) {
    cin >> u >> v;
    adj[--u].push_back(--v);
    adj[v].push_back(u);
    mx[i] = -1;
  }
  findCentroid();
  solve(x), solve(y);
  cout << ans[0].size() << endl;
  for (int i = 0; i < ans[0].size(); i++)
    cout << ans[0][i] << ' ' << ans[1][i] << ' ' << ans[2][i] << endl;
}
