#include <bits/stdc++.h>
using namespace std;
int n;
int ed[1010][2];
struct data {
  int to, nxt;
  int id;
} mp[2020];
int head[1010], cnt;
void link(int x, int y, int id) {
  mp[++cnt].to = y;
  mp[cnt].nxt = head[x];
  mp[cnt].id = id;
  head[x] = cnt;
}
int root;
int siz[2020];
int ma[2020];
void dfs(int x, int fa) {
  siz[x] = 1;
  ma[x] = 0;
  int v;
  for (int i = head[x]; i; i = mp[i].nxt)
    if (mp[i].to != fa) {
      v = mp[i].to;
      dfs(v, x);
      siz[x] += siz[v];
      ma[x] = max(ma[x], siz[v]);
    }
  ma[x] = max(ma[x], n - siz[x]);
  if (ma[x] < ma[root]) root = x;
}
bool cmp(int a, int b) { return siz[a] > siz[b]; }
int rs[2020], tot;
int bel[2020];
int A, B;
int ans[2020];
int cla;
int da[2020];
void dfsa(int x, int fa, int fid) {
  ++cla;
  da[x] = cla;
  ans[fid] = da[x] - da[fa];
  int v;
  for (int i = head[x]; i; i = mp[i].nxt)
    if (mp[i].to != fa) {
      v = mp[i].to;
      dfsa(v, x, mp[i].id);
    }
}
int clb;
int db[2020];
void dfsb(int x, int fa, int fid) {
  ++clb;
  db[x] = clb * (A + 1);
  ans[fid] = db[x] - db[fa];
  int v;
  for (int i = head[x]; i; i = mp[i].nxt)
    if (mp[i].to != fa) {
      v = mp[i].to;
      dfsb(v, x, mp[i].id);
    }
}
int main() {
  scanf("%d", &n);
  int xx, yy;
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &xx, &yy);
    link(xx, yy, i);
    link(yy, xx, i);
    ed[i][0] = xx;
    ed[i][1] = yy;
  }
  ma[0] = 23336666;
  dfs(1, 0);
  dfs(root, 0);
  for (int i = head[root]; i; i = mp[i].nxt) rs[++tot] = mp[i].to;
  sort(rs + 1, rs + tot + 1, cmp);
  int p, fl = 0;
  for (p = 1; A < (n - 1) / 3; ++p) A += siz[rs[p]];
  p--;
  B = n - 1 - A;
  if (B < (n - 1) / 3) {
    if (siz[p] < (n - 1) / 3) {
      A -= siz[rs[p]];
      B += siz[rs[p]];
      p--;
    } else {
      fl = 1;
      bel[p] = 1;
      B = siz[rs[p]];
    }
  }
  if (!fl)
    for (int i = p + 1; i <= tot; ++i) bel[i] = 1;
  for (int i = 1; i <= tot; ++i) {
    int id;
    for (int j = head[root]; j; j = mp[j].nxt)
      if (mp[j].to == rs[i]) {
        id = mp[j].id;
        break;
      }
    if (!bel[i])
      dfsa(rs[i], root, id);
    else
      dfsb(rs[i], root, id);
  }
  for (int i = 1; i < n; ++i) printf("%d %d %d\n", ed[i][0], ed[i][1], ans[i]);
  return 0;
}
