n = int(input())
edges = []
degree = [0] * n
ans = []
now = 0
x = -1
for i in range(n - 1):
    edges.append(list(map(lambda x:int(x) - 1, input().split(' '))))
    degree[edges[i][0]] += 1
    degree[edges[i][1]] += 1

for i in range(n):
    if degree[i] >= 3:
        x = i

if x == -1:
    for i in range(n - 1):
        print(i)
    exit()

for i in range(n - 1):
    if edges[i][0] == x or edges[i][1] == x:
        ans.append(now)
        now += 1
    else:
        ans.append(-1)

for i in range(n - 1):
    if ans[i] == -1:
        ans[i] = now
        now += 1

for i in range(n - 1):
    print(ans[i])
