def solve(n, queries):
    node = 0
    count = [0] * (n + 1)
    for u, v in queries:
        count[u] += 1
        count[v] += 1
        if count[u] == 3:
            node = u
        if count[v] == 3:
            node = v
    
    j = 0
    ans = [-1] * len(queries)
    for i, pair in enumerate(queries):
        if node in pair:
            ans[i] = j
            j += 1
    for i in range(len(queries)):
        if ans[i] != -1:
            continue
        ans[i] = j
        j += 1
    for i in ans:
        print(i)


def smain():
    inp = lambda: [int(x) for x in input().split()]
    n =  int(input())
    queries = [inp() for _ in range(n - 1)]
    solve(n, queries)


if __name__ == '__main__':
    smain()

