#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adj[1005];
int pot[1005];
int sz[1005];
int cen;
int treesize(int here, int par) {
  sz[here] = 1;
  for (auto there : adj[here]) {
    if (there == par) continue;
    sz[here] += treesize(there, here);
  }
  return sz[here];
}
int getcentroid(int here, int par, int cap) {
  for (auto there : adj[here]) {
    if (there == par) continue;
    if (sz[there] > cap) return getcentroid(there, here, cap);
  }
  return here;
}
vector<int> nearcen;
vector<int> A, B;
long long sumA, sumB;
long long sum = -1, pl;
long long sum2, pl2;
void dfs(int here, int par, bool start) {
  sum++;
  pot[here] = sum;
  if (par != -1) printf("%d %d %d\n", here, par, pot[here] - pot[par]);
  if (start) {
    for (auto there : A) {
      dfs(there, here, false);
    }
  } else {
    for (auto there : adj[here]) {
      if (there == par) continue;
      dfs(there, here, false);
    }
  }
}
void dfs2(int here, int par, bool start) {
  if (here != cen) pot[here] = sum2;
  sum2 += (sum + 1);
  if (par != -1) printf("%d %d %d\n", here, par, pot[here] - pot[par]);
  if (start) {
    for (auto there : B) {
      dfs2(there, here, false);
    }
  } else {
    for (auto there : adj[here]) {
      if (there == par) continue;
      dfs2(there, here, false);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (long long i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int root = 1;
  int allsize = treesize(1, -1);
  cen = getcentroid(1, -1, allsize / 2);
  treesize(cen, -1);
  for (auto e : adj[cen]) {
    nearcen.push_back(e);
  }
  sort(nearcen.begin(), nearcen.end(),
       [](int a, int b) { return sz[a] > sz[b]; });
  for (long long i = 0; i < nearcen.size(); i++) {
    if (sumA <= sumB) {
      sumA += sz[nearcen[i]];
      A.push_back(nearcen[i]);
    } else {
      sumB += sz[nearcen[i]];
      B.push_back(nearcen[i]);
    }
  }
  dfs(cen, -1, true);
  dfs2(cen, -1, true);
}
