#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 200007;
struct eT {
  void setd(int _u, int _v, int _l) { u = _u, v = _v, last = _l; }
  int u, v, last;
} edge[MAXN * 2], e2[MAXN * 2];
struct aT {
  aT() : x(0), y(0), yy(0) {}
  aT(int _x, int _y, int _yy) : x(_x), y(_y), yy(_yy) {}
  int x, y, yy;
};
int n;
int ke, la[MAXN];
int k2, l2[MAXN];
vector<aT> ans;
vector<int> cent;
vector<pair<int, int> > es;
void init();
void input();
void work();
int getsize(int now, int fa);
pair<int, int> dfs1(int now, int fa);
void tostar(int now, int fa, int end);
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d", &n);
  int u, v;
  ke = 0;
  memset(la, -1, sizeof(la));
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &u, &v);
    edge[ke].setd(u, v, la[u]);
    la[u] = ke++;
    edge[ke].setd(v, u, la[v]);
    la[v] = ke++;
  }
}
void work() {
  getsize(1, -1);
  k2 = 0;
  memset(l2, -1, sizeof(l2));
  for (auto x : cent)
    for (int i = la[x]; ~i; i = edge[i].last) {
      bool flag = true;
      for (auto y : cent)
        if (y == edge[i].v) {
          flag = false;
          break;
        }
      if (flag) {
        es.clear();
        pair<int, int> ret = dfs1(edge[i].v, x);
        for (auto x : es) {
          e2[k2].setd(x.first, x.second, l2[x.first]);
          l2[x.first] = k2++;
          e2[k2].setd(x.second, x.first, l2[x.second]);
          l2[x.second] = k2++;
        }
        tostar(ret.first, x, ret.second);
        ans.push_back(aT(x, ret.first, ret.second));
      }
    }
  printf("%d\n", ans.size());
  for (auto x : ans) printf("%d %d %d\n", x.x, x.y, x.yy);
}
int getsize(int now, int fa) {
  int ns = 0, ret, ms = 0;
  for (int i = la[now]; ~i; i = edge[i].last) {
    if (edge[i].v ^ fa) {
      ret = getsize(edge[i].v, now);
      ns += ret;
      ms = (((ms) > (ret)) ? (ms) : (ret));
    }
  }
  ++ns;
  ms = (((ms) > (n - ns)) ? (ms) : (n - ns));
  if (ms * 2 <= n) cent.push_back(now);
  return ns;
}
pair<int, int> dfs1(int now, int fa) {
  int lt = fa, v, beg = now;
  pair<int, int> ret;
  for (int i = la[now]; ~i; i = edge[i].last) {
    if ((v = edge[i].v) ^ fa) {
      ret = dfs1(v, now);
      if (beg == now) beg = ret.second;
      ans.push_back(aT(lt, now, ret.second));
      if (lt ^ fa) es.push_back(make_pair(lt, ret.second));
      lt = ret.first;
    }
  }
  if (beg ^ now) es.push_back(make_pair(lt, now));
  return make_pair(beg, now);
}
void tostar(int now, int fa, int end) {
  for (int i = l2[now]; ~i; i = e2[i].last) {
    if (e2[i].v ^ fa) {
      tostar(e2[i].v, now, end);
      ans.push_back(aT(now, e2[i].v, end));
    }
  }
}
