from collections import deque

q = deque()

p = 0
n = int(input())
color = [0 for i in range(n)]
mass = [[0] for i in range(n)]
for i in range(n - 1):
    x, y = map(int, input().split())
    mass[x - 1] += [[y - 1, i]]
    mass[y - 1] += [[x - 1, i]]
    mass[x - 1][0] += 1
    mass[y - 1][0] += 1
k = 0
m = []
f = 1
for i in range(n):
    if mass[i][0] == n - 1:
        for i in range(n - 1):
            print(i)
        exit()
    if mass[i][0] == 2:
        k += 1
    if mass[i][0] == 1:
        m += [mass[i][1][1]]
        if f == 1:
            p = i
        f = 0
if k == n - 2:
    for i in range(n - 1):
        print(i)
    exit()
if n == 2:
    print(0)
    print(1)
    exit()
res=[-1 for i in range (n-1)]
if len(m)>=3:
    res[m[0]]=0
    res[m[1]]=1
    res[m[2]]=2
j=3
for i in range (n-1):
    if res[i]==-1:
        print(j)
        j+=1
    else:
        print(res[i])