n = int(input())
neighbours = dict()
labels = [-1]*(n-1)
edges = []
for k in range(n-1):
    u,v = map(int,input().split())
    edges.append(set([u,v]))
    if u in neighbours:
        neighbours[u].append(v)
    else:
        neighbours[u] = [v]
    if v in neighbours:
        neighbours[v].append(u)
    else:
        neighbours[v] = [u]
b = True
j = 1
while b and j < n-1:
    if len(neighbours[j]) >= 3:
        b = False
        for i in range(3):
            ind = edges.index(set([j,neighbours[j][i]]))
            labels[ind] = i
        val = 3
        for k in range(len(labels)):
            if labels[k] == -1:
                labels[k] = val
                val += 1
    j += 1
if b:
    labels = list(range(n-1))

for k in labels:
    print(k)
