#include <bits/stdc++.h>
using namespace std;
template <typename TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << '\n';
}
template <typename TH, typename... TA>
void _dbg(const char *sdbg, TH h, TA... t) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, t...);
}
vector<int> adj[1010];
int n, sz[1010], cnt, label[1010], d[2];
int num[1010];
vector<int> divi[2];
void dfs(int src, int par) {
  sz[src] = 1;
  for (auto &e : adj[src]) {
    if (e != par) {
      dfs(e, src);
      sz[src] += sz[e];
    }
  }
}
int fcnt(int src, int par) {
  for (auto &e : adj[src]) {
    if (e != par and sz[e] > (n >> 1)) {
      return fcnt(e, src);
    }
  }
  return src;
}
void go(int src, int par, int lab) {
  num[src] = divi[lab][d[lab]++];
  cout << par << ' ' << src << ' ' << num[src] - num[par] << '\n';
  for (auto &e : adj[src]) {
    if (e != par) {
      go(e, src, lab);
    }
  }
}
void assign() {
  int csz = 0;
  for (auto &e : adj[cnt]) {
    if (sz[e] >= (n / 3)) {
      label[e] = 1;
      csz = sz[e];
      goto out;
    }
  }
  for (auto &e : adj[cnt]) {
    csz += sz[e];
    label[e] = 1;
    if (csz >= (n / 3)) {
      goto out;
    }
  }
out:
  int m = n - 1 - csz;
  for (int i = 1; i <= m; i++) {
    divi[0].push_back(i);
  }
  for (int i = 1; i <= csz; i++) {
    divi[1].push_back(i * m);
  }
  for (auto &e : adj[cnt]) {
    go(e, cnt, label[e]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  cnt = fcnt(1, 0);
  dfs(cnt, 0);
  (cnt);
  assign();
}
