#include <bits/stdc++.h>
using namespace std;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
const int N = 1e3;
int n, sz[N], rem, val, cen, bst = 1e9, p1;
vector<int> g[N];
bool vis[N];
void print(int u, int p, int is) {
  for (auto i : g[u])
    if (i != p) {
      printf("%d %d %d\n", u + 1, i + 1, (++rem) - is);
      print(i, u, rem);
    }
}
void print1(int u, int p, int is) {
  for (auto i : g[u])
    if (i != p) {
      printf("%d %d %d\n", u + 1, i + 1, (++rem) * val - is);
      print1(i, u, rem * val);
    }
}
void dfs(int u, int p) {
  sz[u] = 1;
  int mx = 1;
  for (auto i : g[u])
    if (i != p) {
      dfs(i, u);
      sz[u] += sz[i];
      mx = max(mx, sz[i]);
    }
  mx = max(mx, n - sz[u]);
  if (mx <= (n + 1) / 2) {
    bst = min(bst, mx);
    if (bst == mx) cen = u, p1 = p;
  }
}
int main() {
  scanf("%d", &n);
  if (n == 1) return 0;
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    g[--u].push_back(--v);
    g[v].push_back(u);
  }
  dfs(0, -1);
  if (p1 != -1) sz[p1] = n - sz[cen];
  sort(g[cen].begin(), g[cen].end(),
       [&](int a, int b) { return sz[a] < sz[b]; });
  int temp = 0;
  for (int i = g[cen].size() - 1; i + 1; i--) {
    if (n - temp - sz[g[cen][i]] <= (n - 1) / 3) continue;
    vis[i] = 1;
    printf("%d %d %d\n", cen + 1, g[cen][i] + 1, ++rem);
    print(g[cen][i], cen, rem);
    temp += sz[g[cen][i]];
  }
  val = rem;
  rem = 0;
  for (int i = 0; i < g[cen].size(); i++)
    if (!vis[i]) {
      printf("%d %d %d\n", cen + 1, g[cen][i] + 1, (++rem) * val);
      print1(g[cen][i], cen, rem * val);
    }
}
