#include <bits/stdc++.h>
using namespace std;
constexpr int N = 2e5;
int n;
set<int> g[N];
int sz[N], tail[N];
vector<tuple<int, int, int>> foo;
void dfs(int u, int p) {
  sz[u] = 1;
  for (int v : g[u])
    if (p != v) dfs(v, u), sz[u] += sz[v];
}
pair<int, int> dfs2(int u, int p) {
  for (int v : g[u])
    if (p != v) {
      if (sz[v] * 2 == n) return {u, v};
      if (sz[v] * 2 > n) return dfs2(v, u);
    }
  return {u, u};
}
void exchange(int u, int v, int w) {
  foo.emplace_back(u, v, w);
  g[u].erase(v);
  g[v].erase(u);
  g[u].insert(w);
  g[w].insert(u);
}
void dfs4(int u, int p) {
  tail[u] = u;
  vector<int> ch;
  for (int v : g[u])
    if (v != p) ch.push_back(v);
  for (int v : ch) dfs4(v, u);
  ch.clear();
  for (int v : g[u])
    if (v != p) ch.push_back(v);
  if (ch.empty()) return;
  int t = tail[ch[0]];
  tail[u] = t;
  while (ch.size() >= 2) {
    int v = ch.back();
    ch.pop_back();
    exchange(p, u, tail[v]);
    tail[tail[v]] = t;
    p = v;
  }
}
void dfs5(int u, int p) {
  vector<int> path = {p, u};
  while (true) {
    int ch = -1;
    for (int v : g[u])
      if (v != p) {
        ch = v;
        break;
      }
    if (ch == -1) break;
    p = u;
    u = ch;
    path.push_back(u);
  }
  for (int i = (int)path.size() - 4; i >= 0; i--) {
    foo.emplace_back(path[i], path[i + 1], path[path.size() - 2]);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    g[u].insert(v);
    g[v].insert(u);
  }
  int x, y;
  dfs(0, -1);
  tie(x, y) = dfs2(0, -1);
  if (x == y) {
    vector<int> ch(g[x].begin(), g[x].end());
    for (int v : ch) dfs4(v, x);
    for (int v : g[x]) dfs5(v, x);
  } else {
    vector<int> chx(g[x].begin(), g[x].end());
    vector<int> chy(g[y].begin(), g[y].end());
    for (int v : chx)
      if (v != y) dfs4(v, x);
    for (int v : chy)
      if (v != x) dfs4(v, y);
    for (int v : g[x])
      if (v != y) dfs5(v, x);
    for (int v : g[y])
      if (v != x) dfs5(v, y);
  }
  cout << foo.size() << endl;
  for (auto p : foo) {
    int u, v, w;
    tie(u, v, w) = p;
    printf("%d %d %d\n", u + 1, v + 1, w + 1);
  }
}
