from collections import defaultdict, Counter
from bisect import bisect, bisect_left
from math import sqrt, gcd, ceil, factorial
from heapq import heapify, heappush, heappop


MOD = 10**9 + 7
inf = float("inf")
ans_ = []

def nin():return int(input())
def ninf():return int(file.readline())

def st():return (input().strip())
def stf():return (file.readline().strip())

def read(): return list(map(int, input().strip().split()))
def readf():return list(map(int, file.readline().strip().split()))

    
# ans_ = ""


# file = open("input.txt", "r")
def solve():
    ans_ = ""
    n = nin(); deg = defaultdict(int)
    arr = [];
    for i in range(n-1):
        u, v = read()
        deg[u]+=1; deg[v] += 1
        arr.append((u, v))
        
    x = 0; m=n-2; s = defaultdict(int)
    for i in arr:
        u, v = i
        if deg[u] == 1 or deg[v] == 1:ans_+= str(x)+"\n"; x += 1
        else:ans_+= str(m)+"\n"; m -= 1
    
    print(ans_)
        
# file.close()
solve()

# for i in ans_:print(i)
    