#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << '{';
  for (int i = (0), __i = (((int)(vec).size())); i < __i; i++) {
    os << vec[i];
    if (i + 1 != ((int)(vec).size())) os << ',';
  }
  os << '}';
  return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &par) {
  os << '(' << par.first << ',' << par.second << ')';
  return os;
}
int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
template <class T>
T sqr(T x) {
  return x * x;
}
const long long MOD = 1e9 + 7;
long long bin_pow(long long base, long long p) {
  if (p == 1) return base;
  if (p % 2 == 0) {
    long long t = bin_pow(base, p / 2);
    return t * t % MOD;
  } else
    return bin_pow(base, p - 1) * base % MOD;
}
long long inverse_element(long long x) { return bin_pow(x, MOD - 2); }
long long divide(long long a, long long b) {
  return a * inverse_element(b) % MOD;
}
long long mult(long long a, long long b) { return (a * b) % MOD; }
vector<int> g[202020];
int p[202020];
int ed[202020];
int d[202020];
bool used[202020];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = (0), __i = (n - 1); i < __i; i++) {
    int a, b;
    cin >> a >> b;
    g[a - 1].push_back(b - 1);
    g[b - 1].push_back(a - 1);
  }
  if (n <= 3) {
    cout << 0;
    return 0;
  }
  vector<int> ans;
  stack<int> st;
  st.push(0);
  p[0] = -1;
  while (!st.empty()) {
    int u = st.top();
    if (ed[u] == ((int)(g[u]).size())) {
      d[u]++;
      if (p[u] != -1) d[p[u]] += d[u];
      st.pop();
      continue;
    }
    int v = g[u][ed[u]++];
    if (v != p[u]) {
      p[v] = u;
      st.push(v);
    }
  }
  vector<int> centroids;
  int u = 0;
  while (true) {
    bool cent = (n - d[u] <= n / 2);
    int cur = u;
    for (int i = (0), __i = (((int)(g[u]).size())); i < __i; i++) {
      int v = g[u][i];
      if (v == p[u]) continue;
      if (d[v] > n / 2) {
        u = v;
        cent = false;
        break;
      } else if (d[v] == n / 2) {
        u = v;
        break;
      }
    }
    if (cent) {
      centroids.push_back(cur);
      used[cur] = true;
    }
    if (cur == u) break;
  }
  for (int i = (0), __i = (n); i < __i; i++) d[i] = ed[i] = 0;
  for (int j = (0), __j = (((int)(centroids).size())); j < __j; j++) {
    for (int i = (0), __i = (((int)(g[centroids[j]]).size())); i < __i; i++) {
      if (used[g[centroids[j]][i]]) continue;
      vector<pair<int, int> > leaves;
      st.push(g[centroids[j]][i]);
      p[g[centroids[j]][i]] = centroids[j];
      int deep = 0;
      while (!st.empty()) {
        int u = st.top();
        if (ed[u] == ((int)(g[u]).size())) {
          if (ed[u] == 1) leaves.push_back({deep, u});
          st.pop();
          deep--;
          continue;
        }
        int v = g[u][ed[u]++];
        if (!used[v] && v != p[u]) {
          p[v] = u;
          st.push(v);
          deep++;
        }
      }
      sort((leaves).begin(), (leaves).end());
      for (int i = (0), __i = (((int)(leaves).size()) - 1); i < __i; i++) {
        int u = leaves[i].second;
        while (ed[u] < 3) {
          d[p[u]] = u;
          u = p[u];
        }
        d[leaves[i].second] = p[u];
        ed[u]--;
        ans.push_back(p[u]);
        ans.push_back(u);
        ans.push_back(leaves[i].second);
        while (u != d[leaves[i].second]) {
          p[u] = d[u];
          u = d[u];
        }
      }
      if (((int)(leaves).size()) > 0) {
        int leaf = leaves[((int)(leaves).size()) - 1].second;
        int u = p[leaf];
        while (!used[u]) {
          ans.push_back(p[u]);
          ans.push_back(u);
          ans.push_back(leaf);
          u = p[u];
        }
      }
    }
  }
  cout << ((int)(ans).size()) / 3;
  for (int i = (0), __i = (((int)(ans).size()) / 3); i < __i; i++) {
    cout << endl
         << ans[i * 3] + 1 << ' ' << ans[i * 3 + 1] + 1 << ' '
         << ans[i * 3 + 2] + 1 << ' ';
  }
  return 0;
}
