"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by enraged(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
import heapq
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var))
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [[val for i in range(n)] for j in range(m)]


def maxDeg():
    for i in graph.keys():
        if len(graph[i]) >= 3:
            return i
    return 0


n = int(data())
graph = dd(set)
mat = []
for i in range(n-1):
    a, b = sp()
    mat.append((a, b))
    graph[a].add(b)
    graph[b].add(a)
m = maxDeg()
if m == 0:
    for i in range(n-1):
        out(str(i)+"\n")
    exit()
dist = len(graph[m])-1
length = dist
s = set()
j = dist+1
for i in mat:
    if i[0] == m and dist >= 0:
        out(str(length-dist)+"\n")
        dist -= 1
    elif i[1] == m and dist >= 0:
        out(str(length-dist)+"\n")
        dist -= 1
    else:
        out(str(j)+"\n")
        j += 1
