import sys
input = sys.stdin.readline
n = int(input())
dg = 10**6
edge = [[] for i in range(n+1)]
p = []

for i in range(n-1):
    u,v = map(int,input().split())
    edge[u].append(v)
    edge[v].append(u)
    p.append(u*dg+v)

q = -1
for i in range(1,n+1):
    if len(edge[i]) >= 3:
        q = i
        break

if q == -1:
    for i in range(n-1):
        print(i)
else:
    X = 0
    mi = 3
    for e in p:
        a,b = e//dg,e%dg
        if q in (a,b):
            if X != 3:
                print(X)
                X += 1
            else:
                print(mi)
                mi += 1
        else:
            print(mi)
            mi += 1