#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void __print(long long x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const long long MAX = 200005;
bool cen[MAX];
vector<long long> P[MAX];
long long n, sub[MAX], centroid, w1, w2;
struct zap {
  long long from, to1, to2;
};
vector<zap> ans;
void dfs1(long long u, long long fa) {
  sub[u]++;
  bool t = true;
  for (auto it : P[u]) {
    if (it != fa) {
      dfs1(it, u);
      sub[u] += sub[it];
      if (sub[it] > n / 2) t = false;
    }
  }
  if (n - sub[u] > n / 2) t = false;
  cen[u] = t;
}
void dfs2(long long u, long long fa) {
  if (u != w1)
    ans.push_back({centroid, w2, u}), w2 = u, ans.push_back({u, fa, w1});
  for (auto it : P[u])
    if (it != fa) dfs2(it, u);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i <= n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    P[a].push_back(b);
    P[b].push_back(a);
  }
  dfs1(1, -1);
  for (long long i = 1; i <= n; i++) {
    if (cen[i]) {
      centroid = i;
      for (auto it : P[i]) {
        if (!cen[it]) {
          w1 = it, w2 = it;
          dfs2(it, centroid);
          if (w1 != w2) ans.push_back({centroid, w2, w1});
        }
      }
    }
  }
  cout << ans.size() << "\n";
  for (auto it : ans) cout << it.from << " " << it.to1 << " " << it.to2 << "\n";
  return 0;
}
