import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


def in_list():
    return (list(map(int, input().split())))


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


def in_ints():
    return (map(int, input().split()))


n = in_int()


g = [[] for i in range(n+1)]
e = [-1]*(n-1)


vv = 0
mx = 0
for xx in range(n-1):
    u, v  = in_ints()

    g[u].append((v,xx))
    if len(g[u]) > mx:
        mx = len(g[u])
        vv = u

    g[v].append((u,xx))
    if len(g[v]) > mx:
        mx = len(g[v])
        vv = v


count  = 0

for v, i in g[vv]:
    if e[i] == -1:
        e[i] = count
        count +=1


for i in range(len(e)):
    if e[i] == -1:
        e[i] = count
        count += 1
    print(e[i])
