import time,math
from sys import stdin,stdout
from collections import deque
import bisect
from fractions import Fraction
pi=3.14159265358979323846264338327950
def I():
    return (stdin.readline())
def In():
    return map(int,stdin.readline().split())
def L():
    return list(map(int,stdin.readline().split()))
def Si():
    return sorted(list(map(int,stdin.readline().split())))
def Si():
    return sorted(list(map(int,stdin.readline().split())),reverse=True)
def P(x):
    return stdout.write(str(x)+"\n")
def Pi(x,y):
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b):
    return (a*b)//gcd(a,b)
def gcd(a,b):
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree():
    v=int(input())
    li=[set() for i in range(v+1)]
    l=[]
    for i in range(v-1):
        u1,u2=In()
        li[u1].add(u2)
        li[u2].add(u1)
        l.append([u1,u2])
    return li,v,l
#####################################################################################

def bfs(adj,v):
    visited=[False]*(v+1)
    visited[1]=True
    q=deque()
    q.append(1)
    while q:
        ele=q.pop()
        if len(adj[ele])>=3:
            note=ele
            return True,note
        for sml in adj[ele]:
            if visited[sml]==False:
                q.append(sml)
                visited[sml]=True
    return False,-1

def solve():
    adj,v,l=readTree()
    stm,val=bfs(adj,v)
    if stm==False:
        li=[i for i in range(v-1)]
        for ele in li:
            P(ele)
    else:
        u=[0,1,2]
        avail=[i for i in range(3,v-1)]
        for ele in l:
            u1,u2=ele[0],ele[1]
            if u1==val or u2==val:
                if u:
                    print(u.pop())
                else:
                    print(avail.pop())
            else:
                print(avail.pop())
solve()