import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
n=int(input())
tree=[[] for i in range(n)] ; s=[]
for _ in range(n-1):
    a,b=map(int,input().split())
    s.append([a-1,b-1])
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
ans=[-1]*(n-1) ; maxx=0 ; ind=-1
for i in range(len(tree)):
    if len(tree[i])>maxx:
        maxx=len(tree[i])
        ind=i
st=deque([int(i) for i in range(n-1)])
for i in range(len(s)):
    if ind in s[i]:
        ans[i]=st.popleft()
for i in range(len(ans)):
    if ans[i]==-1:
        ans[i]=st.pop()
for i in range(len(ans)):
    print(ans[i])
            
    
    
            