import sys
import collections
n = int(sys.stdin.readline())
adj = {}
res = []
for _ in range(n-1):
    u,v = map(int,sys.stdin.readline().split())
    res.append((min(u,v),max(u,v)))
    if adj.get(u) == None:
        adj[u] = [v]
    else:
        adj[u].append(v)
    if adj.get(v) == None:
        adj[v] = [u]
    else:
        adj[v].append(u)
        
maxx = 0
for j in adj:
    l = len(adj[j])
    if maxx<l:
        maxx = l
        root_node = j

visited = {}
queue = collections.deque([root_node]) 
visited[root_node] = 1
mex_val = 0
answer = {}
while len(queue)!=0:
    head = queue.popleft()
#     print(head)
    for ed in adj[head]:
        if visited.get(ed) == None:
            answer[(min(head,ed),max(head,ed))] = mex_val
            mex_val+=1
            visited[ed] = 1
            queue.append(ed)
for item in res:
    # print(answer[item])
    sys.stdout.write(str(answer[item]))
    sys.stdout.write("\n")