n = int(input())
ans = [-1] * (n-1)
d = dict()
for i in range(1, n+1):
    d[i] = dict()
for i in range(n-1):
    u, v = map(int, input().split())
    d[u][v] = i
    d[v][u] = i

cnt = 0
for i in range(1, n+1):
    if len(d[i]) >= 3:
        for j in d[i].values():
            ans[j] = cnt
            cnt+=1
        break

for i in range(len(ans)):
    if ans[i] == -1:
        ans[i] = cnt
        cnt += 1
    print(ans[i])
            
        