#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, rt, size;
vector<int> e[N];
int sz[N], mx[N], cnt = 1, t = 1;
void getrt(int u, int ff) {
  sz[u] = 1;
  for (auto v : e[u])
    if (v != ff) {
      getrt(v, u), sz[u] += sz[v], mx[u] = max(mx[u], sz[v]);
    }
  mx[u] = max(mx[u], n - sz[u]);
  if (mx[u] < size) size = mx[u], rt = u;
}
void init(int u, int ff) {
  sz[u] = 1;
  for (auto v : e[u])
    if (v != ff) init(v, u), sz[u] += sz[v];
}
inline bool cmp(const int &x, const int &y) { return sz[x] > sz[y]; }
void dfs1(int u, int ff, int w) {
  printf("%d %d %d\n", ff, u, cnt - w);
  int tw = cnt;
  ++cnt;
  for (auto v : e[u])
    if (v != ff) dfs1(v, u, tw);
}
void dfs2(int u, int ff, int w) {
  printf("%d %d %d\n", ff, u, cnt * t - w);
  int tw = cnt * t;
  ++t;
  for (auto v : e[u])
    if (v != ff) dfs2(v, u, tw);
}
int main() {
  scanf("%d", &n);
  for (int i = (2); i <= (n); i++) {
    int x, y;
    scanf("%d%d", &x, &y), e[x].push_back(y), e[y].push_back(x);
  }
  size = n, getrt(1, 0), init(rt, 0);
  sort(e[rt].begin(), e[rt].end(), cmp);
  for (auto v : e[rt]) {
    if (cnt * 3 < n)
      dfs1(v, rt, 0);
    else
      dfs2(v, rt, 0);
  }
  return 0;
}
