from collections import defaultdict
g = defaultdict(list)
n = int(input())
arr = []
for _ in range(n-1):
    u,v = map(int,input().split(' '))
    arr.append([u,v,-1])
    g[u].append(v)
    g[v].append(u)

    
for key,val in g.items():
    if len(val)==1:
        a = key
        break
    
stack = [a]
v = [False]*(n+1)
v[a] = True
l = []
while len(stack)>0:
    t = stack.pop()
    if len(g[t])>=3:
        l = g[t]
        break
    else:
        for child in g[t]:
            if v[child]==False:
                stack.append(child)
                v[child]=True
for item in arr:
    if (item[0]==a and item[1]==g[a][0]) or (item[0]==g[a][0] and item[1]==a):
        item[2] = 0 
        
i = 1
if len(l)>0:
    for item in l:
        for p in arr:
            if (p[0]==item and p[1]==t) or (p[0]==t and p[1]==item):
                p[2] = i
                i = i + 1 
    
for item in arr:
    if item[2]==-1:
        item[2] = i 
        i = i + 1 
        
for item in arr:
    print(item[2])