import sys
input=sys.stdin.readline
from math import *
from collections import deque 
def bfs(a,i,vis,s):
    q=deque()
    q.append(i)
    r=0
    vis[1]=1
    while len(q)!=0:
        z=q.popleft()
        for j in a[z]:
            if vis[j]==0:
                s[str(min(z,j))+"*"+str(max(z,j))]=r
                r+=1
                vis[j]=1
                q.append(j)
                #print(s)
  
    
n=int(input())
a=[[] for i in range(n+1)]
b=[]
for i in range(n-1):
    x,y=map(int,input().split())
    a[x].append(y)
    a[y].append(x)
    b.append([x,y])
s={}
vis=[0 for i in range(n+1)]
bfs(a,1,vis,s)
for i in range(len(b)):
    m1=min(b[i])
    m2=max(b[i][0],b[i][1])
    print(s[str(m1)+"*"+str(m2)])
