import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline

n = int(input())
g = [[] for _ in range(n)]

for i in range(n-1):
    u, v = map(int, input().split())
    u, v = u-1, v-1
    g[u].append([v, i])
    g[v].append([u, i])

ans = [0]*(n-1)
from collections import deque
d = deque(range(n-1))

def dfs(v, p=-1):
  for u, ei in g[v]:
    if u == p:
      continue
    else:
        if len(g[u]) == 1:
            ans[ei] = d.popleft()
        else:
            ans[ei] = d.pop()
    dfs(u, v)

dfs(0)
for i in range(n-1):
  print(ans[i])
