import collections
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
vis = set()
vis.add(root)
q = collections.deque([root])
mex = 0
ans = {}
while len(q)!=0:
    head = q.popleft()
    for edge in adj[head]:
        if edge not in vis:
            ans[tuple(sorted((head,edge)))] = mex
            mex += 1
            vis.add(edge); q.append(edge)
for i in temp:
    sys.stdout.write(str(ans[i]))
    sys.stdout.write('\n')