from sys import stdin

d = {}
pair = []
l = int(stdin.readline())
v = [-1]*(l-1)
for _ in range(l-1):
    
    #n = int(stdin.readline())
    n = [int(i) for i in stdin.readline().split(" ")]
    pair.append(n)
    key1, key2 = str(n[0]), str(n[1])
    if key1 not in d:
        d[key1] = 1
    else:
        d[key1] += 1 
    if key2 not in d:
        d[key2] = 1
    else:
        d[key2] += 1

#print(pair)
#print(d)
values = list(d.values())
values = list(sorted(set(values)))
#print(values)

flag = 0

for key, value in d.items(): 
    if value>2:
        flag = 1
        temp1 = 0
        temp2 = 3
        key = int(key)
        for i in range(l): 
            if pair[i][0]==key or pair[i][1]==key:
                v[i] = temp1
                temp1 += 1
                if(temp1>2):
                    break
                    
        for i in range(l-1):
            if v[i]!=-1:
                print(v[i])
            else:
                print(temp2)
                temp2 += 1
        break


if flag==0:
    for i in range(0,l-1):
        print(i)