

"""
NTC here
"""
import sys
inp = sys.stdin.readline
def input(): return inp().strip()
# flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**26)

def iin(): return int(input())


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


# range = xrange
# input = raw_input

def BFS(s, adj, step):
    parent = {s: None}
    ans = {}
    ch = 0
    u = [s]
    while u:  # runs till u is []
        nextu = []
        for i in u:
            for v in adj[i]:
                if v not in parent:
                    ans[(v, i)]=step[ch]
                    ch+=1
                    parent[v] = i
                    nextu.append(v)
        u = nextu.copy()
    return ans
def main():
    T = 1
    while T:
        T-=1
        n = iin()
        e = [ lin() for i in range(n-1)]
        adj = [[] for i in range(n+1)]
        for i, j in e:
            adj[i].append(j)
            adj[j].append(i)
        s = 1
        for i in range(n+1):
            if len(adj[i])>len(adj[s]):s=i
        set1 = list(range(0, n-1, 2))+list(range(1, n-1, 2))[::-1]
        ans = BFS(s, adj, set1)
        # print(ans)
        for i, j in e:
            if (i, j) in ans:
                print(ans[(i, j)])
            else:
                print(ans[(j, i)])
        


            
            

main()

# threading.Thread(target=main).start()


"""
1
5
1 3
1 4
1 6
2 6
0 5
"""