from sys import stdin
import sys

tt = 1

for loop in range(tt):

    n = int(stdin.readline())

    lis = [ [] for i in range(n)]
    for i in range(n-1):
        u,v = map(int,stdin.readline().split())
        u -= 1
        v -= 1

        lis[u].append((v,i))
        lis[v].append((u,i))

    one = []
    for i in range(n):
        if len(lis[i]) == 1:
            one.append(i)

    ans = [None] * (n-1)
    cnt = 0
    for i in one:
        for v,ind in lis[i]:
            if ans[ind] == None:
                ans[ind] = cnt
                cnt += 1

    for i in range(n-1):
        if ans[i] == None:
            ans[i] = cnt
            cnt += 1

    print ("\n".join(map(str,ans)))
