import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def solve():
    n = ni()
    if n == 2:
        print(0)
        return
    edges = [tuple(nm()) for _ in range(n-1)]
    ans = [-1]*(n-1)
    G = [list() for _ in range(n)]
    for i, (u, v) in enumerate(edges):
        u -= 1; v -= 1
        G[u].append((i, v))
        G[v].append((i, u))
    c = 0
    for i in range(n):
        if len(G[i]) == 1:
            ans[G[i][0][0]] = c
            c += 1
    for i in range(n-1):
        if ans[i] < 0:
            ans[i] = c
            c += 1
    print(*ans, sep='\n')
    return

solve()

# T = ni()
# for _ in range(T):
#     solve()
