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)
    lis[b].append(a)
    index[b].append(_)
    index[a].append(_)
pos = -1
for i in range(len(lis)):
    if len(lis[i]) >= 3  :
        pos = i
        break
flag = [-1] * (n-1)
ite  = 1
if pos != -1:
    for i in range(len(index[pos])):
        ans[index[pos][i]] = ite
        flag[index[pos][i]] = 1
        ite+=1
    for i in range(n):
        if pos != i :
            for j in range(len(lis[i])):
                if flag[index[i][j]] == -1:
                    ans[index[i][j]] = ite
                    ite+=1
                    flag[index[i][j]] = 1

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

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