#include <bits/stdc++.h>
using namespace std;
struct node {
  int to;
  node *next;
};
struct rec {
  int a, b, c;
};
int cen1, cen2, i, j, m, n, cen, cnt, cntans;
int size[200005], ver[200005], ind[200005], now[200005], dep[200005];
node *nd[200005];
rec ans[400005];
bool centroid[200005];
void addd(int u, int v) {
  node *p = new node();
  p->to = v;
  p->next = nd[u];
  nd[u] = p;
}
void dfs0(int u, int pre) {
  node *p;
  p = nd[u];
  while (p) {
    if ((p->to != pre) && (p->to != cen1) && (p->to != cen2)) {
      dep[p->to] = dep[u] + 1;
      dfs0(p->to, u);
    }
    p = p->next;
  }
}
void dfs2(int u, int pre) {
  node *p;
  node *pp;
  p = nd[u];
  if ((u != cen) && (u != ver[cnt])) {
    ind[u] = cnt;
    cntans++;
    ans[cntans].a = cen;
    ans[cntans].b = now[cnt];
    ans[cntans].c = u;
    now[cnt] = u;
    pp = nd[u];
    while (pp) {
      if (pp->to != cen) {
        if (dep[u] > dep[pp->to]) {
          cntans++;
          ans[cntans].a = u;
          ans[cntans].b = pp->to;
          ans[cntans].c = ver[cnt];
        }
      }
      pp = pp->next;
    }
  }
  while (p) {
    if ((p->to != pre) && (p->to != cen1) && (p->to != cen2)) {
      if (u == cen) {
        cnt++;
        ver[cnt] = p->to;
        now[cnt] = p->to;
      }
      dfs2(p->to, u);
    }
    p = p->next;
  }
}
void dfs(int u, int pre) {
  node *p;
  p = nd[u];
  size[u] = 1;
  while (p) {
    if (p->to != pre) {
      dfs(p->to, u);
      size[u] += size[p->to];
      if (size[p->to] * 2 > n) centroid[u] = false;
    }
    p = p->next;
  }
  if (2 * (n - size[u]) > n) centroid[u] = false;
}
int main() {
  cnt = cntans = 0;
  scanf("%d", &n);
  int x, y;
  for (i = 1; i <= n - 1; i++) {
    scanf("%d%d", &x, &y);
    addd(x, y);
    addd(y, x);
  }
  for (i = 1; i <= n; i++) centroid[i] = true;
  dfs(1, -1);
  for (i = 1; i <= n; i++) {
    if (centroid[i]) {
      if (cen1 == 0)
        cen1 = i;
      else
        cen2 = i;
    }
  }
  cen = cen1;
  dfs0(cen, -1);
  dfs2(cen, -1);
  for (i = 1; i <= cnt; i++) {
    cntans++;
    ans[cntans].a = cen;
    ans[cntans].b = now[i];
    ans[cntans].c = ver[i];
  }
  cnt = 0;
  cen = cen2;
  dfs0(cen, -1);
  dfs2(cen, -1);
  for (i = 1; i <= cnt; i++) {
    cntans++;
    ans[cntans].a = cen;
    ans[cntans].b = now[i];
    ans[cntans].c = ver[i];
  }
  printf("%d\n", cntans);
  for (i = 1; i <= cntans; i++) {
    printf("%d %d %d\n", ans[i].a, ans[i].b, ans[i].c);
  }
  return 0;
}
