#author: riyan

if __name__ == '__main__':
    n = int(input())
    edges = []
    adj_vec = {}
    for i in range(n - 1):
        u, v = map(int, input().split())
        edges.append([(u, v), -1])
        if u not in adj_vec.keys():
            adj_vec[u] = []
        adj_vec[u].append(v)
        if v not in adj_vec.keys():
            adj_vec[v] = []
        adj_vec[v].append(u)

    bamboo = True
    for i in range(1, n + 1):
        if len(adj_vec[i]) >= 3:
            mn = i
            bamboo = False
            break
    
    if bamboo:
        for i in range(n - 1):
            print(i)
    else:
        cnt = 0
        for i in range(n - 1):
            u, v = edges[i][0]
            if u == mn or v == mn:
                edges[i][1] = cnt
                cnt += 1
        for i in range(n - 1):
            if edges[i][1] == -1:
                edges[i][1] = cnt
                cnt += 1
            print(edges[i][1])
        
    