import math
from bisect import bisect_left, bisect_right
from sys import stdin, stdout, setrecursionlimit
from collections import Counter
input = lambda: stdin.readline().strip()
print = stdout.write

n = int(input())
graph = [0]
edge = [0]
for i in range(1, n+1):
    graph.append(0)
    edge.append(0)
for i in range(n-1):
    a, b = map(int, input().split())
    graph[a]+=1
    graph[b]+=1
    edge[a] = i
    edge[b] = i
ans = []
for i in range(n-1):
    ans.append(-1)
i = 0
for k in range(1, n+1):
    v = graph[k]
    if v==1 and i<min(3, n-1):
        ans[edge[k]] = i
        i+=1
j = 3
for i in range(len(ans)):
    if ans[i]==-1:
        ans[i] = j
        j+=1
for i in ans:
    print(str(i)+'\n')
