import sys
input = sys.stdin.readline
from collections import deque, defaultdict

def bfs(s):
    visited = [False]*n
    visited[s] = True
    q = deque([s])
    c = 0
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if not visited[nv]:
                k = min(v, nv)*10**6+max(v, nv)
                ans[k] = c
                visited[nv] = True
                q.append(nv)
                c += 1

n = int(input())
d = [0]*n
G = [[] for _ in range(n)]
edges = []

for _ in range(n-1):
    u, v = map(int, input().split())
    d[u-1] += 1
    d[v-1] += 1
    G[u-1].append(v-1)
    G[v-1].append(u-1)
    edges.append((min(u-1, v-1), max(u-1, v-1)))

ans = defaultdict(int)

for i in range(n):
    if d[i]>=3:
        mark = i
        break
else:
    mark = 0
    
bfs(mark)

for u, v in edges:
    print(ans[u*10**6+v])