import sys;
from sys import stdin, stdout
adj = [[] for i in range(10**5+7)];

#def dfs()


n = int(input());
query = []
for i in range(n-1):
    u,v = map(int,input().split());
    query.append([u,v]);
    adj[u].append(v);
    adj[v].append(u);

flag = True;
vertex = -1;
for i in range(n+1):
    if(len(adj[i])>=3):
        flag=False;
        vertex=i;
        
if(flag):
    for i in range(n-1):
#        print(i);
        stdout.write(str(i)+"\n")
    sys.exit();
color = [adj[vertex][0],adj[vertex][1],adj[vertex][2]];
cnt = 3;
for i in range(n-1):
    if(query[i][0]==vertex and query[i][1] in color):
        #print(color.index(query[i][1]));
        stdout.write(str(color.index(query[i][1]))+"\n")
    elif(query[i][1]==vertex and query[i][0] in color):
        #print(color.index(query[i][0]));
        stdout.write(str(color.index(query[i][0]))+"\n")
    else:
        stdout.write(str(cnt)+"\n");
        #print(cnt);
        cnt+=1;

        
