node_dict = {}
flag = True
mat = []
target = -1
n = int(input())
for t in range(n-1):
    u,v = map(int,input().split())
    mat.append((u,v))
    if flag:
        try:
            node_dict[u] += 1
            if node_dict[u] == 3:
                target = u
                flag = False
        except KeyError:
            node_dict[u] = 1
            
        try:
            node_dict[v] += 1
            if node_dict[v] == 3:
                target = v
                flag = False
        except KeyError:
            node_dict[v] = 1
            
edges = n-2
count = 0
for (u,v) in mat:
    if u == target or v == target:
        print(count)
        count += 1
    else:
        print(edges)
        edges -= 1
    