import atexit, io, sys 
 
  
# A stream implementation using an in-memory bytes  
# buffer. It inherits BufferedIOBase. 
 
buffer = io.BytesIO() 
 
sys.stdout = buffer
 
  
# print via here 
 
@atexit.register 
 
def write(): 
 
    sys.__stdout__.write(buffer.getvalue()) 






n=input()
adj=[[] for j in range(n+1)]
deg=[[0,j] for j in range(n+1)]
edge=[-1 for j in range(n-1)]

for _ in range(n-1):
    a,b=map(int,raw_input().split())
    deg[a][0]+=1
    deg[b][0]+=1
    adj[a].append([b,_]);adj[b].append([a,_])
deg=sorted(deg)
v=0
for i in range(1,n+1):
    if v==n-1 or deg[i][0]>1 or v==2:
        break
    p=deg[i][1]
    
    k=adj[p]
    for h in k:
        if v==(n-1):
            break
        if edge[h[1]]==-1:
            edge[h[1]]=v;v+=1
for i in edge:
    if i==-1:
        print v;
        v+=1
    else:
        print i