from collections import defaultdict

n = int(raw_input())
m = n-1
deg = defaultdict(int)
adj = defaultdict(list)
for i in range(m):
    a, b = map(int, raw_input().split())
    deg[a] += 1
    deg[b] += 1
    adj[a].append((b, i))
    adj[b].append((a, i))
sor = sorted(deg.items(), key=lambda x: -x[1])
res = [-1]*(n-1)
cnt = 0
# print(sor)
for x, y in sor:
    for b in adj[x]:
        # print(b, cnt, res)
        if res[b[1]] != -1:
            continue
        res[b[1]] = cnt
        cnt += 1
for x in res:
    print(x)
