N = int(input())

degree = [0 for _ in range(N+1)]
adj_list = [[] for _ in range(N+1)]

edges = []

leaves = []
for _ in range(N-1):
    [u,v] = list(map(int,input().split()))
    adj_list[u].append(v)
    adj_list[v].append(u)
    edges.append((u,v))
for n in range(1,N+1):
    if len(adj_list[n]) == 1:
        leaves.append(n)

labels = {}
l0 = leaves[0]
(u0,v0) = (l0, adj_list[l0][0])
labels[(u0,v0)] = 0
labels[(v0,u0)] = 0

l1 = leaves[1]
(u1,v1) = (l1, adj_list[l1][0])
labels[(u1,v1)] = 1
labels[(v1,u1)] = 1

ctr = 2
if len(leaves) > 2:
    l2 = leaves[-1]
    (u,v) = (l2, adj_list[l2][0])
    labels[(u,v)] = 2
    labels[(v,u)] = 2
    ctr += 1

for (u,v) in edges:
    if (u,v) in labels:
        print(labels[(u,v)])
    else:
        print(ctr)
        ctr+=1

