#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector<vector<int>> g;
vector<int> s, ms;
vector<vector<int>> ind;
int S = 0;
void add_edge(int x, int y) { g[x].push_back(y); }
void init() {
  cin >> n;
  g.resize(n + 1, vector<int>());
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    add_edge(x, y);
    add_edge(y, x);
  }
}
void dfs(int x, int fa) {
  s[x] = 1;
  for (int y : g[x]) {
    if (y == fa) continue;
    dfs(y, x);
    s[x] += s[y];
    ms[x] = max(ms[x], s[y]);
  }
  ms[x] = max(ms[x], n - s[x]);
}
void dfs_print(int x, int fa, int prefixNum, int delta) {
  for (int y : g[x]) {
    if (y == fa) continue;
    S += delta;
    cout << y << " " << x << " " << S - prefixNum << endl;
    dfs_print(y, x, S, delta);
  }
}
void work() {
  s.resize(n + 1, 0);
  ms.resize(n + 1, 0);
  dfs(1, -1);
  int C = 0;
  for (int i = 1; i <= n; i++) {
    if (C == 0 || ms[i] < ms[C]) {
      C = i;
    }
  }
  s.resize(n + 1, 0);
  dfs(C, -1);
  vector<pair<int, int>> e;
  for (int i = 0; i < g[C].size(); i++) {
    int v = g[C][i];
    e.push_back(make_pair(s[v], v));
  }
  sort(e.begin(), e.end(), greater<pair<int, int>>());
  int sum[2] = {0, 0};
  vector<int> can[2] = {vector<int>(), vector<int>()};
  for (int i = 0; i < e.size(); i++) {
    if (sum[0] < sum[1]) {
      can[0].push_back(e[i].second);
      sum[0] += e[i].first;
    } else {
      can[1].push_back(e[i].second);
      sum[1] += e[i].first;
    }
  }
  S = 0;
  for (int v : can[0]) {
    S += 1;
    cout << C << " " << v << " " << S << endl;
    dfs_print(v, C, S, 1);
  }
  S = 0;
  for (int v : can[1]) {
    S += (sum[0] + 1);
    cout << C << " " << v << " " << S << endl;
    dfs_print(v, C, S, sum[0] + 1);
  }
}
int main() {
  init();
  work();
  return 0;
}
