#include <bits/stdc++.h>
using namespace std;
const int N = 2024;
int n, vis[N], sz[N], d[N][N];
vector<int> g[N];
inline void centroid_dfs(int i, int pa) {
  sz[i] = 1;
  for (int j : g[i])
    if (j != pa) {
      centroid_dfs(j, i);
      sz[i] += sz[j];
    }
}
inline bool is_centroid(int i) {
  centroid_dfs(i, -1);
  for (int j : g[i])
    if (sz[j] > n / 2) return 0;
  return 1;
}
inline int get_centroid() {
  for (int i = 0, ggd = n; i < ggd; i++)
    if (is_centroid(i)) return i;
  assert(0);
}
inline void assign(int i, int pa, int st, int take, vector<int>& v) {
  d[i][pa] = d[pa][i] = v[st] - take;
  int cur = st + 1;
  for (int j : g[i])
    if (j != pa) {
      assign(j, i, cur, v[st], v);
      cur += sz[j];
    }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0, ggd = n - 1; i < ggd; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int c = get_centroid(), suml = 0, sumr = 0;
  vector<int> l, r, v_l, v_r;
  priority_queue<pair<int, vector<int>>, vector<pair<int, vector<int>>>,
                 greater<pair<int, vector<int>>>>
      pq;
  for (int i : g[c]) pq.push({sz[i], {i}});
  while (((int)(pq).size()) > 2) {
    auto t1 = pq.top();
    pq.pop();
    auto t2 = pq.top();
    pq.pop();
    for (auto it : t2.second) t1.second.push_back(it);
    t1.first += t2.first;
    pq.push(t1);
  }
  if (((int)(pq).size())) l = pq.top().second, suml = pq.top().first, pq.pop();
  if (((int)(pq).size())) r = pq.top().second, sumr = pq.top().first, pq.pop();
  for (int i = 0, ggd = suml; i < ggd; i++) v_l.push_back(i + 1);
  for (int i = 0, ggd = sumr; i < ggd; i++) v_r.push_back((suml + 1) * (i + 1));
  int l_id = 0, r_id = 0;
  for (int i : l) assign(i, c, l_id, 0, v_l), l_id += sz[i];
  for (int i : r) assign(i, c, r_id, 0, v_r), r_id += sz[i];
  for (int i = 0, ggd = n; i < ggd; i++)
    for (int j = i + 1, ggd = n; j < ggd; j++)
      if (d[i][j]) cout << i + 1 << " " << j + 1 << " " << d[i][j] << "\n";
}
