#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int head[N], sz[N], cnt = 0;
struct Edge {
  int v, next;
} edge[N << 1];
vector<int> vec;
bool cmp(int a, int b) { return sz[a] < sz[b]; }
void add(int u, int v) {
  edge[++cnt] = (Edge){v, head[u]};
  head[u] = cnt;
}
void dfs(int x, int fa) {
  sz[x] = 1;
  for (int i = head[x]; i; i = edge[i].next)
    if (edge[i].v != fa) dfs(edge[i].v, x), sz[x] += sz[edge[i].v];
}
void dfs2(int x, int fa, int res) {
  int tmp = res;
  for (int i = head[x]; i; i = edge[i].next)
    if (edge[i].v != fa) {
      printf("%d %d %d\n", x, edge[i].v, tmp);
      dfs2(edge[i].v, x, res), tmp += res * sz[edge[i].v];
    }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i <= (n - 1); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v), add(v, u);
  }
  for (int rt = (1); rt <= (n); ++rt) {
    dfs(rt, 0), vec.clear();
    for (int i = head[rt]; i; i = edge[i].next) vec.push_back(edge[i].v);
    sort(vec.begin(), vec.end(), cmp);
    int sum = 0;
    for (int i = 0; i < vec.size(); ++i) {
      sum += sz[vec[i]];
      if ((sum + 1) * (n - sum - 1) >= (2 * n * n) / 9) {
        int res = 1;
        for (int j = (0); j <= (i); ++j) {
          printf("%d %d %d\n", rt, vec[j], res);
          dfs2(vec[j], rt, 1), res += sz[vec[j]];
        }
        res = sum + 1;
        for (int j = i + 1; j < vec.size(); ++j) {
          printf("%d %d %d\n", rt, vec[j], res);
          dfs2(vec[j], rt, sum + 1), res += sz[vec[j]] * (sum + 1);
        }
        return 0;
      }
    }
  }
}
