from collections import *
n = int(input())
g = defaultdict(set)
all = Counter()
l = []
ans = [-1 for i in range(n-1)]
camein = [[]]*(n + 10)
if n == 2:
    print(0)
    exit()
elif n == 3:
    print(0,1)
    exit()
done = 1
for i in range(n - 1):
    a,b = [int(i) for i in input().split()]
    l.append(set([a,b]))
    g[a].add(b)
    g[b].add(a)
    all[a] += 1
    all[b] += 1
    camein[a].append(i)
    camein[b].append(i)
    if done:
        if len(g[a]) == 3:
            curr = 0
            for k in camein[a]:
                ans[k] = curr
                curr += 1
            done = 0
        elif len(g[b]) == 3:
            for k in camein[b]:
                ans[k] = curr
                curr += 1
            done = 0
for i in range(n - 1):
    if ans[i] == -1:
        ans[i] = curr
        curr += 1
print(*ans[:-1],sep='\n')

