import sys
input = sys.stdin.readline
n = int(input())

from collections import defaultdict
deg = defaultdict(int)
uvl = []
for _ in range(n-1):
    u,v = map(int,input().split())
    uvl.append((u-1,v-1))
    deg[u-1] += 1
    deg[v-1] += 1

nidx = 0

ansl = [-1 for i in range(n-1)]

for idx, (u,v) in enumerate(uvl):
    if deg[u] == 1 or deg[v] == 1:
        ansl[idx] = nidx
        nidx += 1

for i in range(n-1):
    if ansl[i] == -1:
        ansl[i] = nidx
        nidx += 1

for a in ansl:
    print(a)


