#include <bits/stdc++.h>
using namespace std;
void Debug() { cout << '\n'; }
template <class FIRST, class... REST>
void Debug(FIRST arg, REST... rest) {
  cout << arg << " ";
  Debug(rest...);
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  if (!v.empty()) {
    for (int i = int(0); i < int((int)(v).size() - 1); i++) out << v[i] << ", ";
    out << v.back();
  }
  out << "]";
  return out;
}
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& v) {
  out << "(" << v.first << ", " << v.second << ")";
  return out;
}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const long long mod = 1000000007;
const int inf = 1 << 29;
const long long linf = 1LL << 60;
const double PI = 3.14159265358979323846;
int N;
vector<int> G[MAX_N];
int S[MAX_N];
bool cen[MAX_N];
vector<int> C;
vector<int> sub[MAX_N], pre[MAX_N];
vector<vector<int> > ans;
int dfs(int v, int p) {
  int cnt = 1;
  bool ok = true;
  for (int i = int(0); i < int((int)(G[v]).size()); i++) {
    int n = G[v][i];
    if (n == p) continue;
    int a = dfs(n, v);
    if (a > N / 2) ok = false;
    cnt += a;
  }
  if (N - cnt > N / 2) ok = false;
  if (ok) {
    C.push_back(v);
    cen[v] = true;
  }
  return cnt;
}
void dfs2(int v, int p, int c) {
  if (v != c && p != c) {
    sub[c].push_back(v);
    pre[c].push_back(p);
  }
  for (int i = int(0); i < int((int)(G[v]).size()); i++) {
    int n = G[v][i];
    if (p == n) continue;
    dfs2(n, v, c);
  }
}
void solve() {
  cin >> N;
  for (int i = int(0); i < int(N - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(0, -1);
  for (int i = int(0); i < int((int)(C).size()); i++) {
    int v = C[i];
    for (int j = int(0); j < int((int)(G[v]).size()); j++) {
      int n = G[v][j];
      if (cen[n]) continue;
      dfs2(n, v, n);
      int k = (int)(sub[n]).size();
      if (k == 0) continue;
      ans.push_back({v, n, sub[n][0]});
      for (int j = int(0); j < int(k - 1); j++) {
        int a = sub[n][j], b = pre[n][j], c = sub[n][j + 1];
        ans.push_back({a, b, n});
        ans.push_back({v, a, c});
      }
      int a = sub[n][k - 1], b = pre[n][k - 1];
      ans.push_back({a, b, n});
      ans.push_back({v, a, n});
    }
  }
  cout << (int)(ans).size() << "\n";
  for (int i = int(0); i < int((int)(ans).size()); i++) {
    cout << ans[i][0] + 1 << " " << ans[i][1] + 1 << " " << ans[i][2] + 1
         << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed;
  cout.precision(20);
  solve();
  return 0;
}
