#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using db = double;
using pii = pair<int, int>;
struct Ope {
  int x, y, z;
};
vector<Ope> sol;
const int mxn = 200006;
int s[mxn];
vi e[mxn];
int size(int x, int p) {
  s[x] = 1;
  for (auto i : e[x])
    if (i != p) s[x] += size(i, x);
  return s[x];
}
int core(int x, int p) {
  for (auto i : e[x])
    if (i != p)
      if (s[x] - s[i] < s[i]) return s[x] -= s[i], s[i] += s[x], core(i, x);
  return x;
}
bool v[mxn];
int n;
set<int> E[mxn];
void ope(int x, int y, int z) {
  sol.push_back({x, y, z});
  E[x].erase(y);
  E[y].erase(x);
  E[x].insert(z);
  E[z].insert(x);
}
pii chain(int x, int p) {
  vector<pii> u;
  int o = p;
  for (auto i : e[x])
    if (i != p) {
      auto t = chain(i, x);
      u.push_back(t);
    }
  int FIR = 0;
  for (auto i : u) {
    if (!FIR) FIR = i.second;
    ope(o, x, i.second);
    o = i.first;
  }
  if (FIR == 0) FIR = x;
  return {FIR, x};
}
int flower(int x, int p) {
  int y = 0;
  for (auto i : E[x])
    if (i != p) {
      y = flower(i, x);
      break;
    }
  if (y) {
    ope(p, x, y);
    return y;
  } else {
    return x;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
    E[x].insert(y);
    E[y].insert(x);
  }
  size(1, 0);
  vi co;
  int c = core(1, 0);
  co.push_back(c);
  v[c] = true;
  for (auto i : e[c])
    if (s[i] * 2 == n) {
      v[i] = true;
      co.push_back(i);
    }
  for (auto i : co)
    for (auto j : e[i])
      if (!v[j]) {
        flower(chain(j, i).first, i);
      }
  cout << sol.size() << endl;
  for (auto i : sol) printf("%d %d %d\n", i.x, i.y, i.z);
  return 0;
}
