#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
vector<int> v[N];
int n, sz[N], root1, root2, root3;
struct Node {
  int x, y, y2;
};
vector<Node> ans;
void dfs(int x, int fa) {
  int t;
  sz[x] = 1;
  bool pd = true;
  for (int i = 0; i < v[x].size(); i++)
    if ((t = v[x][i]) != fa) {
      dfs(t, x);
      sz[x] += sz[t];
      if (sz[t] > n >> 1) pd = false;
    }
  if (pd && n - sz[x] <= n >> 1) root3 = x;
  if (sz[x] == n >> 1 && n - sz[x] <= n >> 1) {
    root1 = x, root2 = fa;
  }
}
int q[N], head, tail, d[N];
bool pd[N];
void dfs3(int x, int fa) {
  int t;
  if (v[x].size() == 1) q[++tail] = x;
  for (int i = 0; i < v[x].size(); i++)
    if ((t = v[x][i]) != fa) {
      dfs3(t, x);
    }
}
void dfs2(int &x, int fa) {
  int t = -1;
  if (head <= tail) {
    ans.push_back({fa, x, q[head]});
    d[x]--;
    if (d[x] == 1) q[++tail] = x;
    x = q[head++];
  } else
    return;
  pd[x] = true;
  for (int i = 0; i < v[x].size(); i++)
    if (!pd[v[x][i]]) {
      dfs2(t = v[x][i], x);
      ans.push_back({fa, x, t}), x = t;
      break;
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) d[i] = v[i].size();
  dfs(1, 0);
  if (root1 != 0 && n % 2 == 0) {
    int t;
    pd[root2] = pd[root1] = true;
    for (int i = 0; i < v[root2].size(); i++) {
      t = v[root2][i];
      if (t == root1) continue;
      head = 0, tail = -1;
      dfs3(t, root2);
      dfs2(t, root2);
    }
    for (int i = 0; i < v[root1].size(); i++) {
      t = v[root1][i];
      if (t == root2) continue;
      head = 0, tail = -1;
      dfs3(t, root1);
      dfs2(t, root1);
    }
  } else {
    int t;
    pd[root3] = true;
    for (int i = 0; i < v[root3].size(); i++) {
      t = v[root3][i];
      head = 0, tail = -1;
      dfs3(t, root3);
      dfs2(t, root3);
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++)
    printf("%d %d %d\n", ans[i].x, ans[i].y, ans[i].y2);
  return 0;
}
