#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  int c = getchar(), f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == 45) f = -1;
  for (; isdigit(c); c = getchar()) (x *= 10) += f * (c - '0');
}
int n, m, rt, sz[1000 + 5], d[1000 + 5];
vector<int> G[1000 + 5];
vector<pair<int, int> > son;
bool f[1000 + 5];
void get_sz(int u, int fa) {
  sz[u] = 1;
  for (int v : G[u])
    if (v ^ fa) get_sz(v, u), sz[u] += sz[v];
}
int get_rt(int u, int fa) {
  for (int v : G[u])
    if (v ^ fa)
      if (sz[v] * 2 >= n) return get_rt(v, u);
  return u;
}
void DFS(int u, int fa, int I) {
  printf("%d %d %d\n", fa, u, ((d[u] = ++m) - d[fa]) * I);
  for (int v : G[u])
    if (v ^ fa) DFS(v, u, I);
}
int main() {
  read(n);
  for (int i = 1, u, v; i < n; i++)
    read(u), read(v), G[u].push_back(v), G[v].push_back(u);
  get_sz(1, 0), rt = get_rt(1, 0), get_sz(rt, 0);
  for (int v : G[rt]) son.push_back(pair<int, int>(sz[v], v));
  sort(son.begin(), son.end());
  int cur = 0;
  for (pair<int, int> p : son)
    if (cur + p.first <= n * 2 / 3)
      DFS(p.second, rt, 1), f[p.second] = true, cur += p.first;
  m = 0;
  for (pair<int, int> p : son)
    if (!f[p.second]) DFS(p.second, rt, cur + 1);
  return 0;
}
