#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 50;
int n, sz[N], rt, Mx;
vector<int> G[N];
int fa[N];
int fnd(int x) { return x == fa[x] ? x : fa[x] = fnd(fa[x]); }
void pre_dfs(int u, int f) {
  sz[u] = 1;
  int mx = 0;
  for (int v : G[u])
    if (v != f) pre_dfs(v, u), mx = max(mx, sz[v]), sz[u] += sz[v];
  mx = max(mx, n - sz[u]);
  if (mx < Mx) Mx = mx, rt = u;
}
void dfs(int u, int f) {
  sz[u] = 1;
  for (int v : G[u])
    if (v != f) dfs(v, u), sz[u] += sz[v];
}
int all, _all;
void work(int x, int f, int c) {
  int dt = all + 1 - c;
  cout << x << " " << f << " " << dt << '\n';
  c = ++all;
  for (int v : G[x])
    if (v != f) work(v, x, c);
}
void _work(int x, int f, int c) {
  int dt = _all + 1 - c;
  cout << x << " " << f << " " << dt * (all + 1) << '\n';
  c = ++_all;
  for (int v : G[x])
    if (v != f) _work(v, x, c);
}
int main() {
  cin >> n;
  if (n == 1) return 0;
  for (int i = 1, u, v; i < n; i++)
    scanf("%d%d", &u, &v), G[u].push_back(v), G[v].push_back(u);
  Mx = n, pre_dfs(1, 0), dfs(rt, 0);
  set<pair<int, int> > S;
  for (int z : G[rt]) S.insert(pair<int, int>(sz[z], z));
  for (int z : G[rt]) fa[z] = z;
  while (S.size() > 2) {
    auto a = S.begin(), b = a;
    ++b;
    if (a->first + b->first > n / 2) break;
    fa[fnd(a->second)] = fnd(b->second);
    S.insert(pair<int, int>(a->first + b->first, b->second));
    S.erase(a), S.erase(b);
  }
  auto t = S.end();
  --t;
  for (int z : G[rt])
    if (fnd(z) == t->second) work(z, rt, 0);
  for (int z : G[rt])
    if (fnd(z) != t->second) _work(z, rt, 0);
  return 0;
}
