#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n, sz[maxn], a[maxn], rt, mx, num;
int cnt, head[maxn], to[maxn << 1], nxt[maxn << 1];
vector<int> v;
void add(int x, int y) {
  cnt++;
  to[cnt] = y;
  nxt[cnt] = head[x];
  head[x] = cnt;
}
void work(int x, int fa, int p) {
  num++;
  a[x] = num;
  printf("%d %d %d\n", fa, x, (a[x] - a[fa]) * p);
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y == fa) {
      continue;
    }
    work(y, x, p);
  }
}
void dfs(int x, int fa) {
  sz[x] = 1;
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y == fa) {
      continue;
    }
    dfs(y, x);
    if (min(sz[x], n - sz[x]) > mx) {
      mx = min(sz[x], n - sz[x]);
      rt = x;
    }
    sz[x] += sz[y];
  }
  if (sz[x] * (n - sz[x]) >= (n * n * 2 / 9)) {
    work(x, fa, 1);
    num = 0;
    for (int i = head[fa]; i; i = nxt[i]) {
      int y = to[i];
      if (y != x) {
        work(y, fa, sz[x]);
      }
    }
    exit(0);
  }
  if (min(sz[x], n - sz[x]) > mx) {
    mx = min(sz[x], n - sz[x]);
    rt = x;
  }
}
bool cmp(int x, int y) { return sz[x] < sz[y]; }
int main() {
  scanf("%d", &n);
  if (n == 1) {
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  dfs(rt, 0);
  for (int i = head[rt]; i; i = nxt[i]) {
    int y = to[i];
    v.push_back(y);
  }
  sort(v.begin(), v.end(), cmp);
  int tmp = 0, i;
  for (i = 0; i < v.size() && tmp * (n - tmp) < (n * n * 2 / 9); i++) {
    tmp += sz[v[i]];
    work(v[i], rt, 1);
  }
  num = 0;
  for (; i < v.size(); i++) {
    work(v[i], rt, tmp);
  }
  return 0;
}
