import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    to=[[] for _ in range(n)]
    deg=[0]*n
    for i in range(n-1):
        u,v=MI1()
        to[u].append((v,i))
        to[v].append((u,i))
        deg[u]+=1
        deg[v]+=1
    mx=max(deg)
    if mx<3:ans=list(range(n-1))
    else:
        ans=[-1]*(n-1)
        u=deg.index(mx)
        c=0
        for v,i in to[u]:
            if c==3:break
            ans[i]=c
            c+=1
        for i in range(n-1):
            if ans[i]!=-1:continue
            ans[i]=c
            c+=1
    print(*ans,sep="\n")

main()