from collections import defaultdict, deque
n=int(input())
A=[]
for _i in range(n-1):
    l=tuple(int(x) for x in input().strip().split(" "))
    A.append(l)
hmap=defaultdict(list)
for a,b in A:
    hmap[a].append(b)
    hmap[b].append(a)

visited=[False]*(n+1)
res=dict()

for x in range(1,n+1):
    if len(hmap[x])<=2:
        root=x
        break
Q=deque()
Q.append(root)
count=0
visited=[False]*(n+1)
visited[root]=True
while Q:
    root=Q[0]
    Q.popleft()
    for x in hmap[root]:
        if not visited[x]:
            res[(root,x)]=count
            res[(x,root)]=count
            count+=1
            visited[x]=True
            Q.append(x)

for x in A:
    print(res[x])
