#include <bits/stdc++.h>
struct info {
  int x, index;
  info(int x, int index) : x(x), index(index) {}
};
std::vector<info> graph[100010];
int result[100010];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    graph[u].push_back(info(v, i));
    graph[v].push_back(info(u, i));
    result[i] = -1;
  }
  if (n == 2) {
    printf("0\n");
    return 0;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (graph[i].size() == 1) {
      result[graph[i][0].index] = cnt++;
    }
  }
  for (int i = 1; i < n; i++) {
    if (result[i] == -1)
      printf("%d\n", cnt++);
    else
      printf("%d\n", result[i]);
  }
}
