#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
int n, m, rt, sz[MAXN], d[MAXN];
vector<int> G[MAXN];
vector<pair<int, int> > son;
bool f[MAXN];
void get_sz(int u, int fa) {
  sz[u] = 1;
  for (int v : G[u])
    if (v != fa) {
      get_sz(v, u);
      sz[u] += sz[v];
    }
}
int get_rt(int u, int fa) {
  for (int v : G[u])
    if (v != fa) {
      if (sz[v] * 2 >= n) return get_rt(v, u);
    }
  return u;
}
void dfs(int u, int fa, int I) {
  printf("%d %d %d\n", fa, u, ((d[u] = ++m) - d[fa]) * I);
  for (int v : G[u])
    if (v != fa) dfs(v, u, I);
}
int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  get_sz(1, 0);
  rt = get_rt(1, 0);
  get_sz(rt, 0);
  for (int v : G[rt]) son.push_back(make_pair(sz[v], v));
  sort(son.begin(), son.end());
  int cur = 0;
  for (pair<int, int> p : son) {
    if (cur + p.first <= n * 2 / 3) {
      dfs(p.second, rt, 1);
      f[p.second] = true;
      cur += p.first;
    }
  }
  m = 0;
  for (pair<int, int> p : son)
    if (!f[p.second]) dfs(p.second, rt, cur + 1);
  return 0;
}
