from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import random
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')): 
    #------------------Sublime--------------------------------------#
    sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
    def I():return (int(input()))
    def In():return(map(int,input().split()))
else:
    #------------------PYPY FAst I/o--------------------------------#
    def I():return (int(stdin.readline()))
    def In():return(map(int,stdin.readline().split()))
#sys.setrecursionlimit(1500)
def dict(a):
    d={} 
    for x in a:
        if d.get(x,-1)!=-1:
            d[x]+=1
        else:
            d[x]=1
    return d
def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bi.bisect_left(a, x)
    if i != len(a):
        return i
    else:            
        return -1


def main():
    try:
        n=I()
        d=defaultdict(list)
        ans=-1
        d1={}
        l=[]
        for x in range(n-1):
            a,b=In()
            d[a].append(b)
            d[b].append(a)
            temp=(min(a,b),max(a,b))
            l.append(temp)
            d1[temp]=-1
            if len(d[a])>=3:
                ans=a
            elif len(d[b])>=3:
                ans=b

        if ans==-1:
            for i in range(n-1):
                print(i)
        else:
            i=0
            for x in d[ans]:
                temp=(min(x,ans),max(x,ans))
                d1[temp]=i
                i+=1
            for j in l:
                if d1[j]==-1:
                    d1[j]=i
                    i+=1
            for x in l:
                print(d1[x])

    except:
        pass
        
M = 998244353
P = 1000000007
 
if __name__ == '__main__':
    #for _ in range(I()):main()
    for _ in range(1):main()

    