#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> g[1050];
void addLine(int f, int t) {
  g[f].push_back(t);
  g[t].push_back(f);
}
int siz[1050], rt, minn = 1000000;
void dfs1(int num) {
  siz[num] = 1;
  int sav = 0;
  for (int i = 0, v; i < g[num].size(); i++)
    if (!siz[v = g[num][i]]) {
      dfs1(v);
      siz[num] += siz[v];
      sav = max(sav, siz[v]);
    }
  sav = max(sav, n - siz[num]);
  if (sav < minn) {
    minn = sav;
    rt = num;
  }
}
int bas;
void dfs2(int num, int fa) {
  siz[num] = 1;
  for (int i = 0, v; i < g[num].size(); i++)
    if ((v = g[num][i]) != fa) {
      dfs2(v, num);
      printf("%d %d %d\n", num, v, siz[num] * bas);
      siz[num] += siz[v];
    }
}
int pre[1050], vis[1050];
int main() {
  scanf("%d", &n);
  if (n == 2) {
    puts("1 2 1");
    return 0;
  }
  for (int i = 1, f, t; i < n; i++) {
    scanf("%d%d", &f, &t);
    addLine(f, t);
  }
  dfs1(1);
  pre[0] = -1;
  for (int i = 0; i < g[rt].size(); i++) {
    int c = siz[g[rt][i]], v = g[rt][i];
    for (int j = n - c; j >= 0; j--)
      if (pre[j] != 0 && pre[j + c] == 0) pre[j + c] = v;
  }
  int p, sav = 100000000, sum;
  while (pre[p] == 0) p++;
  for (int i = 0; i < n; i++)
    if (pre[i] != 0 && max(n - i, i) < sav) {
      sav = max(n - i, i);
      p = i;
    }
  sum = bas = 1;
  sav = p;
  for (; p; p = p - siz[pre[p]]) {
    vis[pre[p]] = 1;
    printf("%d %d %d\n", rt, pre[p], sum);
    dfs2(pre[p], rt);
    sum += siz[pre[p]] * bas;
  }
  sum = bas = sav + 1;
  for (int i = 0; i < g[rt].size(); i++)
    if (!vis[g[rt][i]]) {
      printf("%d %d %d\n", rt, g[rt][i], sum);
      dfs2(g[rt][i], rt);
      sum += siz[g[rt][i]] * bas;
    }
  return 0;
}
