#include <bits/stdc++.h>
using namespace std;
static inline void canhazfast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
  T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
  while (b) {
    T q = a / b;
    a %= b;
    swap(a, b);
    x0 -= q * x1;
    swap(x0, x1);
    y0 -= q * y1;
    swap(y0, y1);
  }
  x = x0;
  y = y0;
  return a;
}
static inline int ctz(unsigned x) { return __builtin_ctz(x); }
static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
static inline int clz(unsigned x) { return __builtin_clz(x); }
static inline int clzll(unsigned long long x) { return __builtin_clzll(x); }
static inline int popcnt(unsigned x) { return __builtin_popcount(x); }
static inline int popcntll(unsigned long long x) {
  return __builtin_popcountll(x);
}
static inline int bsr(unsigned x) { return 31 ^ clz(x); }
static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
struct Op {
  int x, y, z;
  Op(int x, int y, int z) : x(x), y(y), z(z) {}
};
vector<int> adj[200016];
int deg[200016];
int n, half;
vector<Op> ans;
vector<int> cids;
int get_cids(int u, int p = 0) {
  int s = 1;
  bool f = true;
  for (int v : adj[u]) {
    if (v == p) continue;
    int t = get_cids(v, u);
    s += t;
    if (t > half) f = false;
  }
  if (f && n - s <= half) cids.push_back(u);
  return s;
}
bool onp[200016];
vector<int> path;
int branch = 0;
void op(int x, int y, int z) { ans.emplace_back(x, y, z); }
void add(int v) {
  path.push_back(v);
  onp[v] = true;
}
void dfs(int u, int p) {
  if (deg[u] == 1) {
    if (!onp[p]) {
      int x = path.back();
      int y = branch;
      op(x, y, u);
      ++deg[u];
      --deg[y];
      branch = 0;
    }
    add(u);
  } else if (onp[p]) {
    if (deg[u] == 2)
      add(u);
    else
      branch = u;
  }
  for (int v : adj[u]) {
    if (v == p) continue;
    dfs(v, u);
    if (onp[u] || !onp[v]) continue;
    if (deg[u] == 2)
      add(u);
    else
      branch = u;
  }
}
void solve(int c) {
  for (int v : adj[c]) {
    path.clear();
    add(c);
    dfs(v, c);
    int sz = (int)path.size();
    int mid = path[sz - 2];
    for (int i = sz - 3; i > 0; --i) op(path[i - 1], path[i], mid);
  }
}
int main() {
  canhazfast();
  cin >> n;
  half = n / 2;
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
    ++deg[a];
    ++deg[b];
  }
  get_cids(1);
  if (cids.size() == 2) {
    int a = cids[0], b = cids[1];
    adj[a].erase(find((adj[a]).begin(), (adj[a]).end(), b));
    adj[b].erase(find((adj[b]).begin(), (adj[b]).end(), a));
  }
  for (int c : cids) solve(c);
  cout << ans.size() << '\n';
  for (Op o : ans) cout << o.x << ' ' << o.y << ' ' << o.z << '\n';
  return 0;
}
