# Author: S Mahesh Raju
# Username: maheshraju2020
# Created on: 25/09/2020 01:23:58

from sys import stdin, stdout, setrecursionlimit
import heapq
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007

n = ii1()
cnt = [0] * n
edges = []
for i in range(n - 1):
    a, b = iia()
    cnt[a - 1] += 1
    cnt[b - 1] += 1
    edges.append([a - 1, b - 1])
cur, end = 0, n - 2
for i in edges:
    if cnt[i[0]] > 1 and cnt[i[1]] > 1:
        print(end)
        end -= 1
    else:
        print(cur)
        cur += 1