#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
set<int> adj[222222];
int parent[222222];
int size[222222];
void dfs0(int v, int p = -1) {
  parent[v] = p;
  size[v] = 1;
  for (int u : adj[v])
    if (u != p) {
      dfs0(u, v);
      size[v] += size[u];
    }
}
vector<tuple<int, int, int>> result;
set<int> centers;
void dfs1(int r, int c, int has, int v, int p) {
  for (int u : adj[v])
    if (u != p) {
      dfs1(r, c, has, u, v);
      has = u;
    }
  result.push_back(tuple<int, int, int>{r, has, v});
  if (v != c) {
    result.push_back(tuple<int, int, int>{v, p, c});
  }
  adj[r].erase(c);
  adj[c].erase(r);
  adj[r].insert(v);
  adj[v].insert(r);
}
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < (N - 1); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    adj[a].insert(b);
    adj[b].insert(a);
  }
  dfs0(0);
  for (int i = 0; i < (N); ++i) {
    if (size[i] * 2 == N)
      centers = {i, parent[i]};
    else {
      bool ok = 2 * (N - size[i]) < N;
      for (int u : adj[i])
        if (u != parent[i]) ok = ok && 2 * size[u] < N;
      if (ok) centers = {i};
    }
  }
  for (int r : centers) {
    vector<int> children(adj[r].begin(), adj[r].end());
    for (int c : children)
      if (centers.find(c) == centers.end()) {
        dfs1(r, c, c, c, r);
      }
  }
  printf("%d\n", result.size());
  for (auto t : result) {
    printf("%d %d %d\n", get<0>(t) + 1, get<1>(t) + 1, get<2>(t) + 1);
  }
}
