#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int n;
vector<int> adjList[1005];
vector<int> subTreeSize(1005);
int dfs(int node, int parent) {
  for (auto itr : adjList[node])
    if (itr != parent) subTreeSize[node] += dfs(itr, node);
  subTreeSize[node]++;
  return subTreeSize[node];
}
int centroid(int node, int parent) {
  for (auto itr : adjList[node])
    if (itr != parent)
      if (subTreeSize[itr] > n / 2) return centroid(itr, node);
  return node;
}
int from[1005], to[1005], weight[1005];
int _i = 0;
int assign(int node, int parent, vector<int> values) {
  sort(values.begin(), values.end());
  int index = 0;
  for (auto itr : adjList[node])
    if (itr != parent) {
      from[_i] = node;
      to[_i] = itr;
      weight[_i] = values[index++];
      _i++;
      vector<int> tempvalues;
      for (int i = 1; i < subTreeSize[itr]; i++)
        tempvalues.push_back(values[index++] - weight[_i - 1]);
      assign(itr, node, tempvalues);
    }
  return 0;
}
void desperate_optimization(bool submitting = true, int precision = 10) {
  if (!submitting) return;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}
int main() {
  desperate_optimization(true);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adjList[u].push_back(v);
    adjList[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) subTreeSize[i] = 0;
  dfs(1, -1);
  int c = centroid(1, -1);
  vector<pair<int, int>> direct;
  for (int i = 1; i <= n; i++) subTreeSize[i] = 0;
  dfs(c, -1);
  for (auto itr : adjList[c]) direct.push_back({subTreeSize[itr], itr});
  sort(direct.begin(), direct.end());
  int index = 0;
  int size = 0;
  while (size < ceil(n / 3)) size += direct[index++].first;
  vector<int> left;
  for (int i = 0; i < index; i++) left.push_back(direct[i].second);
  vector<int> right;
  for (int i = index; i < adjList[c].size(); i++)
    right.push_back(direct[i].second);
  vector<int> leftVals(size);
  for (int i = 0; i < size; i++) leftVals[i] = i + 1;
  index = 0;
  for (auto itr : left) {
    from[_i] = c;
    to[_i] = itr;
    weight[_i] = leftVals[index++];
    _i++;
    vector<int> tempvalues;
    for (int i = 1; i < subTreeSize[itr]; i++)
      tempvalues.push_back(leftVals[index++] - weight[_i - 1]);
    assign(itr, c, tempvalues);
  }
  if (n - size - 1 > 0) {
    vector<int> rightVals(n - size - 1);
    for (int i = 0; i < n - size - 1; i++) rightVals[i] = (i + 1) * (size + 1);
    index = 0;
    for (auto itr : right) {
      from[_i] = c;
      to[_i] = itr;
      weight[_i] = rightVals[index++];
      _i++;
      vector<int> tempvalues;
      for (int i = 1; i < subTreeSize[itr]; i++)
        tempvalues.push_back(rightVals[index++] - weight[_i - 1]);
      assign(itr, c, tempvalues);
    }
  }
  for (int i = 0; i < n - 1; i++)
    cout << from[i] << ' ' << to[i] << ' ' << weight[i] << '\n';
  return 0;
}
