import sys
adj = {}
n = int(sys.stdin.readline())
temp = []
for _ in range(n-1):
    a,b = sys.stdin.readline().split()
    a = int(a); b=int(b)
    temp.append(tuple(sorted((a,b))))
    if a in adj:
        adj[a].append(b)
    else:
        adj[a] = [b]
    if b in adj:
        adj[b].append(a)
    else:
        adj[b] = [a]
m = 0
for i in adj.keys():
    if len(adj[i])>m:
        m = len(adj[i])
        root = i

mex = 0
ans = {}
for edge in adj[root]:
    ans[tuple(sorted((root,edge)))] = mex
    mex += 1
    
for i in temp:
    if i in ans:
        sys.stdout.write(str(ans[i]))
    else:
        sys.stdout.write(str(mex))
        mex += 1
    sys.stdout.write('\n')