import sys
readline = sys.stdin.readline

def parorder(Edge, p):
    N = len(Edge)
    par = [0]*N
    par[p] = -1
    stack = [p]
    order = []
    visited = set([p])
    ast = stack.append
    apo = order.append
    while stack:
        vn = stack.pop()
        apo(vn)
        for vf in Edge[vn]:
            if vf in visited:
                continue
            visited.add(vf)
            par[vf] = vn
            ast(vf)
    return par, order

def getcld(p):
    res = [[] for _ in range(len(p))]
    for i, v in enumerate(p[1:], 1):
        res[v].append(i)
    return res


N = int(readline())
Edge = [[] for _ in range(N)]
Dim = [0]*N
for m in range(N-1):
    a, b = map(int, readline().split())
    a -= 1
    b -= 1
    Edge[a].append((m, b))
    Edge[b].append((m, a))
    Dim[a] += 1
    Dim[b] += 1

if max(Dim) <= 2:
    print('\n'.join(map(str, range(N-1))))
else:
    k = Dim.index(max(Dim))
    Ans = [None]*(N-1)
    remain = set(range(N-1))
    cnt = 0
    for m, vf in Edge[k]:
        Ans[m] = cnt
        remain.remove(cnt)
        cnt += 1
    for i in range(N-1):
        if Ans[i] is None:
            Ans[i] = remain.pop()
    print('\n'.join(map(str, Ans)))

