import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline

n = int(input())
g = [[] for _ in range(n)]

for i in range(n-1):
    u, v = map(int, input().split())
    u, v = u-1, v-1
    g[u].append([v, i])
    g[v].append([u, i])

#print(g)
#print(len(g[1]))
ans = [-1]*(n-1)
k = 0
for i in range(n):
    if len(g[i]) >= 3:
        for u, ei in g[i]:
            ans[ei] = k
            k += 1
        break

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

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