#!/usr/bin/env python3
import sys
from math import *
from collections import defaultdict
from queue import deque                # Queues
from heapq import heappush, heappop    # Priority Queues

# parse
lines = [line.strip() for line in sys.stdin.readlines()]
n = int(lines[0])
ret = [-1 for i in range(n-1)]
edges = []
deg = [0 for i in range(n)]
for i in range(1,n):
  v, u = list(map(int, lines[i].split()))
  v -= 1
  u -= 1
  edges += [(v, u)]
  deg[v] += 1
  deg[u] += 1

cnt = 0
for i in range(n-1):
  if deg[edges[i][0]] == 1 or deg[edges[i][1]] == 1:
    ret[i] = cnt
    cnt += 1

for i in range(n-1):
  if ret[i] == -1:
    ret[i] = cnt
    cnt += 1

for x in ret:
  print(x)
