#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MOD = 1000000007;
const long long UNDEF = -1;
const long long INF = 1e18;
template <typename T>
inline bool chkmax(T &aa, T bb) {
  return aa < bb ? aa = bb, true : false;
}
template <typename T>
inline bool chkmin(T &aa, T bb) {
  return aa > bb ? aa = bb, true : false;
}
static char stdinBuffer[1024];
static char *stdinDataEnd = stdinBuffer + sizeof(stdinBuffer);
static const char *stdinPos = stdinDataEnd;
void readAhead(size_t amount) {
  size_t remaining = stdinDataEnd - stdinPos;
  if (remaining < amount) {
    memmove(stdinBuffer, stdinPos, remaining);
    size_t sz = fread(stdinBuffer + remaining, 1,
                      sizeof(stdinBuffer) - remaining, stdin);
    stdinPos = stdinBuffer;
    stdinDataEnd = stdinBuffer + remaining + sz;
    if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0;
  }
}
int rint() {
  readAhead(16);
  int x = 0;
  bool neg = false;
  while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
  if (*stdinPos == '-') {
    ++stdinPos;
    neg = true;
  }
  while (*stdinPos >= '0' && *stdinPos <= '9') {
    x *= 10;
    x += *stdinPos - '0';
    ++stdinPos;
  }
  return neg ? -x : x;
}
char rch() {
  readAhead(16);
  while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
  char ans = *stdinPos;
  ++stdinPos;
  return ans;
}
long long rlong() {
  readAhead(32);
  long long x = 0;
  bool neg = false;
  while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
  if (*stdinPos == '-') {
    ++stdinPos;
    neg = true;
  }
  while (*stdinPos >= '0' && *stdinPos <= '9') {
    x *= 10;
    x += *stdinPos - '0';
    ++stdinPos;
  }
  return neg ? -x : x;
}
const int mn = 2e5 + 2;
vector<int> g[mn];
vector<int> gfoundCentroid;
int getCentroid(int u, int p, int n) {
  int cnt = 1;
  bool goodCenter = true;
  for (auto v : g[u]) {
    if (v == p) continue;
    int size = getCentroid(v, u, n);
    goodCenter &= size <= n / 2;
    cnt += size;
  }
  goodCenter &= n - cnt <= n / 2;
  if (goodCenter) gfoundCentroid.push_back(u);
  return cnt;
}
vector<pair<int, int> > gdepthv;
int vparent[mn];
void dfs(int x, int p, int depth) {
  vparent[x] = p;
  gdepthv.push_back(make_pair(depth, x));
  for (auto &y : g[x]) {
    if (y == p) continue;
    dfs(y, x, depth + 1);
  }
}
vector<pair<int, pair<int, int> > > gmoves;
inline void mov(int x, int y, int yp) {
  if (y != yp && x != -1) {
    gmoves.push_back(make_pair(x, make_pair(y, yp)));
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n = rint();
  for (int i = 0; i < n - 1; i++) {
    int u = rint(), v = rint();
    g[u].push_back(v);
    g[v].push_back(u);
  }
  getCentroid(1, -1, n);
  assert(gfoundCentroid.size() <= 2);
  assert(gfoundCentroid.size() >= 1);
  for (auto &centroid : gfoundCentroid) {
    for (auto &root : g[centroid]) {
      int lastCh = root;
      bool found = 0;
      for (auto &w : gfoundCentroid) {
        if (w == root) found = 1;
      }
      if (!found) {
        gdepthv.clear();
        dfs(root, centroid, 0);
        sort(gdepthv.begin(), gdepthv.end(), greater<pair<int, int> >());
        for (auto &w : gdepthv) {
          int x = w.second;
          if (x == root) continue;
          mov(centroid, lastCh, x);
          lastCh = x;
          mov(x, vparent[x], root);
        }
      }
      mov(centroid, lastCh, root);
    }
  }
  printf("%d\n", (int)gmoves.size());
  for (auto &w : gmoves) {
    printf("%d %d %d\n", w.first, w.second.first, w.second.second);
  }
}
