#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int v, nex;
} way[200010 << 1];
struct Node {
  int x, y, z;
  Node(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
} a[200010 << 1];
int Num, head[200010], x, y;
int k, n, m, p, L, f[200010], s[200010], sum, root, wss;
bool b[200010];
inline void add(int x, int y) {
  way[++Num].v = y;
  way[Num].nex = head[x];
  head[x] = Num;
}
inline void Dfs(int x, int y) {
  s[x] = 1;
  for (int i = head[x]; i != -1; i = way[i].nex)
    if (way[i].v != y && !b[way[i].v]) {
      Dfs(way[i].v, x);
      s[x] += s[way[i].v];
      f[x] = max(f[x], s[way[i].v]);
    }
  f[x] = max(f[x], sum - s[x]);
  if (f[x] < f[root]) root = x;
}
inline void Dfs2(int x, int y) {
  if (y != sum) {
    a[++wss] = Node(sum, L, x);
    a[++wss] = Node(x, y, k);
    L = x;
  }
  for (int i = head[x]; i != -1; i = way[i].nex)
    if (way[i].v != y) Dfs2(way[i].v, x);
}
inline void Solve(int x, int y) {
  sum = x;
  for (int i = head[x]; i != -1; i = way[i].nex)
    if (way[i].v != y) {
      k = L = way[i].v;
      Dfs2(way[i].v, x);
      a[++wss] = Node(x, L, k);
    }
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  sum = f[0] = n;
  Dfs(1, 0);
  Dfs(root, 0);
  x = 0;
  for (int i = 1; i <= n; i++) {
    if (i != root && s[i] * 2 == n) x = i;
  }
  if (!x)
    Solve(root, 0);
  else
    Solve(root, x), Solve(x, root);
  printf("%d\n", wss);
  for (int i = 1; i <= wss; i++) printf("%d %d %d\n", a[i].x, a[i].y, a[i].z);
  return 0;
}
