import sys
import bisect
# import heapq
from math import ceil,floor,factorial

def c(a,b):
    return int((factorial(a))/((factorial(b)*factorial(a-b))))

RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
mod = 10**9+7
# for _ in range(int(ri())):

n = int(ri())

ans = [0]*(n-1)
lis = [[] for i in range(n)]
index = [[] for i in range(n)]
for _ in range(n-1):
    a,b = RI()
    a-=1
    b-=1
    lis[a].append(b)
    index[a].append(_)
pos = -1
for i in lis:
    if len(i) >= 3  :
        pos = i
        break
ite  = 1
if pos != -1:
    for i in range(len(index[pos])):
        ans[index[pos][i]] = ite
        ite+=1
    for i in range(n):
        if pos != i:
            for j in range(len(lis[i])):
                ans[index[i][j]] = ite
                ite+=1

else:
    for i in range(n):
        for j in range(len(lis[i])):
            ans[index[i][j]] = ite
            ite+=1

for i in range(len(ans)):
    print(ans[i]-1)
