import sys
input = sys.stdin.readline
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]

from collections import *
n = val()
g = defaultdict(set)

l = []
ans = [-1 for i in range(n)]
camein = [set() for i in range(n + 10)]
if n == 2:
    print(0)
    exit()
elif n == 3:
    print(0,1)
    exit()
done = 1
curr = 0
for i in range(n - 1):
    a,b = li()
    g[a].add(b)
    g[b].add(a)
    if done:
        camein[a].add(i)
        camein[b].add(i)
        if len(camein[a]) == 3:
            for k in camein[a]:
                ans[k] = curr
                curr += 1
                if curr == 3:break
            done = 0
            break
        elif len(camein[b]) == 3:
            for k in camein[b]:
                ans[k] = curr
                curr += 1
                if curr == 3:break
            done = 0
            break
for i in range(n - 1):
    if ans[i] != -1:print(ans[i])
    else:
        print(curr)
        curr += 1

