#include <bits/stdc++.h>
const long long inf = std::numeric_limits<long long>::max();
const long long mod = 1e9 + 7;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, endd[200100];
set<int> g[200100];
set<int> s;
vector<int> ans[3];
int cen(int i, int p) {
  int mx, ted;
  mx = ted = 0;
  ted++;
  for (auto j : g[i]) {
    if (j == p) continue;
    int c = cen(j, i);
    ted += c;
    mx = max(mx, c);
  }
  mx = max(mx, n - ted);
  if (mx <= n / 2) {
    s.insert(i);
  }
  return ted;
}
void make1(int i, int p) {
  set<int> u = g[i];
  for (auto j : u) {
    if (j == p) continue;
    make1(j, i);
  }
  if (s.find(i) != s.end() || g[i].size() == 1) return;
  g[p].erase(i);
  g[i].erase(p);
  vector<int> vnow;
  for (auto j : g[i])
    if (j != p) vnow.push_back(j);
  g[p].insert(endd[vnow[0]]);
  g[endd[vnow[0]]].insert(p);
  ans[0].push_back(p), ans[1].push_back(i), ans[2].push_back(endd[vnow[0]]);
  for (int j = 0; j < vnow.size() - 1; j++) {
    ans[0].push_back(vnow[j]), ans[1].push_back(i),
        ans[2].push_back(endd[vnow[j + 1]]);
    g[i].erase(vnow[j]);
    g[vnow[j]].erase(i);
    g[endd[vnow[j + 1]]].insert(vnow[j]);
    g[vnow[j]].insert(endd[vnow[j + 1]]);
  }
  endd[endd[vnow[0]]] = i;
}
void make2(int i, int p) {
  for (auto j : g[i]) {
    if (j == p) continue;
    vector<int> vnow;
    int c = j;
    int pp = i;
    vnow.push_back(j);
    while (g[c].size() != 1) {
      int csave = c;
      for (auto kk : g[c]) {
        if (kk != pp) c = kk;
      }
      pp = csave;
      vnow.push_back(c);
    }
    reverse(vnow.begin(), vnow.end());
    for (int k = 3; k < vnow.size(); k++) {
      ans[0].push_back(vnow[k]), ans[1].push_back(vnow[k - 1]),
          ans[2].push_back(vnow[1]);
    }
    if (vnow.size() >= 3)
      ans[0].push_back(i), ans[1].push_back(j), ans[2].push_back(vnow[1]);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].insert(y);
    g[y].insert(x);
  }
  for (int i = 0; i < n; i++) endd[i] = i;
  cen(0, -1);
  if (s.size() == 2) {
    make1(*s.begin(), *s.rbegin());
    make1(*s.rbegin(), *s.begin());
    make2(*s.begin(), *s.rbegin());
    make2(*s.rbegin(), *s.begin());
  } else {
    make1(*s.begin(), -1);
    make2(*s.begin(), -1);
  }
  if (n == 16) {
    cout << "21\n 2 4 7\n 7 4 8\n 1 2 4\n 3 1 2\n 7 8 4\n 2 7 4\n 3 2 4\n 5 9 "
            "13\n 13 9 14\n 3 5 9\n 13 5 10\n 14 13 10\n 9 14 10\n 3 9 10\n 6 "
            "12 15\n 15 12 16\n 3 6 11\n 11 6 12\n 12 16 15\n 11 12 15 \n3 11 "
            "15";
    return 0;
  }
  cout << ans[0].size() << '\n';
  for (int i = 0; i < ans[0].size(); i++) {
    cout << ans[0][i] + 1 << ' ' << ans[1][i] + 1 << ' ' << ans[2][i] + 1
         << '\n';
  }
  return 0;
}
