#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005][2];
int main() {
  int n, x, y = 0;
  scanf("%d", &n);
  x = n - 1;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &b[i][0], &b[i][1]);
    a[b[i][0]]++;
    a[b[i][1]]++;
  }
  for (int i = 1; i < n; i++) {
    if (a[b[i][0]] == 1 || a[b[i][1]] == 1)
      printf("%d\n", y++);
    else
      printf("%d\n", --x);
  }
}
