#include <bits/stdc++.h>
using namespace std;
int n, u, v, i, head[200005], Next[400005], adj[400005], mx = 1 << 30, ans1,
                                                         ans2, siz[200005], k;
int a[600005], b[600005], c[600005];
void Push(int u, int v) {
  Next[++k] = head[u];
  head[u] = k;
  adj[k] = v;
}
void dfs(int i, int fa) {
  int j, s = 0;
  siz[i] = 1;
  for (j = head[i]; j != 0; j = Next[j])
    if (adj[j] != fa) {
      dfs(adj[j], i);
      siz[i] += siz[adj[j]];
      s = max(s, siz[adj[j]]);
    }
  s = max(s, n - siz[i]);
  if (s == mx) ans2 = i;
  if (s < mx) {
    mx = s;
    ans1 = i;
    ans2 = 0;
  }
}
void Add(int x, int y, int z) {
  a[++k] = x;
  b[k] = y;
  c[k] = z;
}
int now;
void dfs2(int i, int fa, int mr, int root) {
  int j;
  for (j = head[i]; j != 0; j = Next[j])
    if (adj[j] != fa) {
      dfs2(adj[j], i, mr, root);
      Add(root, now, adj[j]);
      Add(adj[j], i, mr);
      now = adj[j];
    }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d %d", &u, &v);
    Push(u, v);
    Push(v, u);
  }
  k = 0;
  dfs(1, 0);
  if (ans2 == 0) {
    for (i = head[ans1]; i != 0; i = Next[i]) {
      now = adj[i];
      dfs2(adj[i], ans1, adj[i], ans1);
      Add(ans1, now, adj[i]);
    }
  } else {
    for (i = head[ans1]; i != 0; i = Next[i])
      if (adj[i] != ans2) {
        now = adj[i];
        dfs2(adj[i], ans1, adj[i], ans1);
        Add(ans1, now, adj[i]);
      }
    for (i = head[ans2]; i != 0; i = Next[i])
      if (adj[i] != ans1) {
        now = adj[i];
        dfs2(adj[i], ans2, adj[i], ans2);
        Add(ans2, now, adj[i]);
      }
  }
  printf("%d\n", k);
  for (i = 1; i <= k; i++) printf("%d %d %d\n", a[i], b[i], c[i]);
}
