#include <bits/stdc++.h>
struct triple {
  int x, y, z;
};
triple make_triple(int x, int y, int z) {
  triple p = {x, y, z};
  return p;
}
const int N = 1 << 18;
int head[N], dst[N + N], nxt[N + N], ie, n, nres;
triple result[N + N];
int roots[2], pa[2], nroot, cur_root, cur_rootpa, cur_root_t;
int readInt() {
  int n = 0;
  int c;
  while ((c = getchar()) <= 32)
    ;
  do n = n * 10 + (c - '0');
  while ((c = getchar()) >= 48);
  return n;
}
void dfs(int cure, int parent) {
  for (int i = head[cure]; i; i = nxt[i])
    if (dst[i] != parent) dfs(dst[i], cure);
  if (cure != cur_root) {
    result[nres++] = make_triple(cur_rootpa, cur_root_t, cure);
    result[nres++] = make_triple(cure, parent, cur_root);
    cur_root_t = cure;
  }
}
void add_result(int cure, int parent) {
  cur_root = cure;
  cur_rootpa = parent;
  cur_root_t = cure;
  dfs(cure, parent);
  result[nres++] = make_triple(parent, cur_root_t, cure);
}
void add_edge(int u, int v) {
  ++ie;
  nxt[ie] = head[u];
  head[u] = ie;
  dst[ie] = v;
}
int dfs_sz(int cure, int parent) {
  static int tsz;
  int sz = 1;
  int mx = 1;
  for (int i = head[cure]; i; i = nxt[i]) {
    if (dst[i] != parent) {
      sz += tsz = dfs_sz(dst[i], cure);
      mx = (mx < tsz ? tsz : mx);
    }
  }
  if (sz * 2 >= n && mx * 2 <= n) {
    pa[nroot] = parent;
    roots[nroot++] = cure;
  }
  return sz;
}
void read_input() {
  n = readInt();
  ie = 0;
  for (int i = 1; i < n; ++i) {
    int u = readInt();
    int v = readInt();
    add_edge(u, v);
    add_edge(v, u);
  }
}
int main() {
  read_input();
  nroot = 0;
  dfs_sz(1, 0);
  nres = 0;
  pa[0] = roots[1];
  pa[1] = roots[0];
  for (int i = 0; i != nroot; ++i) {
    int cure = roots[i], pare = pa[i];
    for (int h = head[cure]; h; h = nxt[h])
      if (dst[h] != pare) add_result(dst[h], cure);
  }
  printf("%d\n", nres);
  for (int i = 0; i != nres; ++i)
    printf("%d %d %d\n", result[i].x, result[i].y, result[i].z);
  return 0;
}
