#include <bits/stdc++.h>
int read() {
  int ans = 0, c, f = 1;
  while (!isdigit(c = getchar()))
    if (c == '-') f *= -1;
  do ans = ans * 10 + c - '0';
  while (isdigit(c = getchar()));
  return ans * f;
}
const int N = 1050;
int n, pre[N], nxt[N * 2], to[N * 2], cnt;
inline void addEdge(int x, int y) {
  nxt[cnt] = pre[x];
  to[pre[x] = cnt++] = y;
  nxt[cnt] = pre[y];
  to[pre[y] = cnt++] = x;
}
int siz[N];
int dfs0(int x, int f) {
  siz[x] = 1;
  for (int i = pre[x]; ~i; i = nxt[i])
    if (to[i] != f) siz[x] += dfs0(to[i], x);
  return siz[x];
}
int cmp(int x, int y) { return siz[x] > siz[y]; }
int P[N], now, addv;
void dfs1(int x, int f, int fv) {
  int xv = now += addv;
  printf("%d %d %d\n", x, f, xv - fv);
  for (int i = pre[x]; ~i; i = nxt[i])
    if (to[i] != f) dfs1(to[i], x, xv);
}
int main() {
  n = read();
  int K = n * n * 2 / 9;
  memset(pre, -1, sizeof pre);
  for (int i = 1; i < n; ++i) addEdge(read(), read());
  dfs0(1, 0);
  int x = 1, f = 0;
  for (int i = pre[x]; ~i;)
    if (siz[to[i]] * 2 >= n && to[i] != f)
      f = x, x = to[i], i = pre[x];
    else
      i = nxt[i];
  dfs0(x, 0);
  int m = 0;
  for (int i = pre[x]; ~i; i = nxt[i]) P[m++] = to[i];
  std::sort(P, P + m, cmp);
  int t = 1, u = 0;
  while (u < m) {
    t += siz[P[u++]];
    if (t * (n - t) >= K) break;
  }
  now = 0, addv = 1;
  for (int i = 0; i < u; ++i) dfs1(P[i], x, 0);
  now = 0, addv = t;
  for (int i = u; i < m; ++i) dfs1(P[i], x, 0);
  return 0;
}
