from sys import stdin
from bisect import bisect_left as bl
from bisect import bisect_right as br

def input():
    return stdin.readline()[:-1]


def intput():
    return int(input())


def sinput():
    return input().split()


def intsput():
    return map(int, sinput())


class RangedList:
    def __init__(self, start, stop, val=0):
        self.shift = 0 - start
        self.start = start
        self.stop = stop
        self.list = [val] * (stop - start)

    def __setitem__(self, key, value):
        self.list[key + self.shift] = value

    def __getitem__(self, key):
        return self.list[key + self.shift]

    def __repr__(self):
        return str(self.list)

    def __iter__(self):
        return iter(self.list)


def dprint(*args, **kwargs):
    if debugging:
        print(*args, **kwargs)


debugging = 1
# Code
n = intput()

matrix = {}
for i in range(1, n + 1):
    matrix[i] = []

conns = []
for _ in range(n - 1):
    u, v = intsput()
    matrix[u].append(v)
    matrix[v].append(u)
    conns.append([u, v])


leafcnt = 0
leaves = []
for i in range(1, n + 1):
    if len(matrix[i]) == 1:
        leaves.append(i)
        leafcnt += 1

if leafcnt >= 3:
    counter = 3
    for conn in conns:
        if leaves[0] in conn:
            print(0)
        elif leaves[1] in conn:
            print(1)
        elif leaves[2] in conn:
            print(2)
        else:
            print(counter)
            counter += 1
else:
    for i in range(len(conns)):
        print(i)
