from collections import Counter, defaultdict, deque
from heapq import heapify, heappush, heappop, heappushpop
from sys import stdin

# int input
int_inp = lambda : int(stdin.readline().strip())
# int array input
lst_inp = lambda : [int(i) for i in stdin.readline().strip().split(" ")]
# string input
str_inp = lambda : stdin.readline().strip()

n = int_inp()
G = Counter()
edges = []
for _ in range(n-1):
    u, v = lst_inp()
    G[u] += 1
    G[v] += 1
    edges.append((u, v))

for u in G:
    if G[u] >= 3:
        deg_3 = u
        break
else:
    deg_3 = -1

cont = 0 if deg_3 == -1 else 3
spec = 0

for u, v in edges:
    if deg_3 in {u, v}:
        print(spec)
        spec += 1
    else:
        print(cont)
        cont += 1
