#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
int rt, mn = 1001, mx[100005], sz[100005], n;
void dfs1(int x, int fa) {
  sz[x] = 1;
  for (auto y : v[x]) {
    if (y == fa) continue;
    dfs1(y, x);
    sz[x] += sz[y];
    mx[x] = max(mx[x], sz[y]);
  }
  mx[x] = max(mx[x], n - sz[x]);
  if (mx[x] < mn) mn = mx[x], rt = x;
}
void dfs2(int x, int fa) {
  sz[x] = 1;
  for (auto y : v[x]) {
    if (y == fa) continue;
    dfs2(y, x);
    sz[x] += sz[y];
  }
}
int base, tot, cnt[100005];
void dfs3(int x, int fa) {
  tot += base;
  cnt[x] = tot;
  printf("%d %d %d\n", x, fa, tot - cnt[fa]);
  for (auto y : v[x]) {
    if (y == fa) continue;
    dfs3(y, x);
  }
}
bool cmp(int x, int y) { return sz[x] < sz[y]; }
int main() {
  int x, y;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs1(1, 0);
  dfs2(rt, 0);
  sort(v[rt].begin(), v[rt].end(), cmp);
  bool f = 0;
  base = 1;
  tot = 0;
  int sum = 0;
  for (auto now : v[rt]) {
    dfs3(now, rt);
    sum += sz[now];
    if (sum >= (n - 1) / 3 && !f) f = 1, base = tot + 1, tot = 0;
  }
}
