#include <bits/stdc++.h>
const int mod = 1000000007;
const int inf = 1000000009;
const long long INF = 1000000000000000009;
const long long big = 1000000000000000;
const long double eps = 0.000000000000000000001;
using namespace std;
vector<int> P[200005];
int D[200005];
bool C[200005];
int N;
void dfs(int n, int p) {
  D[n] = 1;
  bool czy = true;
  for (auto v : P[n]) {
    if (v != p) {
      dfs(v, n);
      D[n] += D[v];
      if (D[v] > N / 2) czy = 0;
    }
  }
  if (N - D[n] > N / 2) czy = 0;
  C[n] = czy;
}
int c = 0, k1, k2;
vector<pair<pair<int, int>, int> > W;
void dfs2(int n, int p) {
  if (n != k1) {
    W.push_back(make_pair(make_pair(c, k2), n));
    k2 = n;
    W.push_back(make_pair(make_pair(n, p), k1));
  }
  for (auto v : P[n])
    if (v != p) dfs2(v, n);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int n;
  cin >> n;
  N = n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    P[a].push_back(b);
    P[b].push_back(a);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    if (C[i]) {
      c = i;
      for (auto v : P[i]) {
        if (!C[v]) {
          k1 = v, k2 = v;
          dfs2(v, c);
          if (k1 != k2) W.push_back(make_pair(make_pair(c, k2), k1));
        }
      }
    }
  }
  cout << W.size() << "\n";
  for (auto v : W)
    cout << v.first.first << " " << v.first.second << " " << v.second << "\n";
  return 0;
}
