MOD = 1000000007
MOD2 = 998244353
ii = lambda: int(input())
si = lambda: input()
dgl = lambda: list(map(int, input()))
f = lambda: map(int, input().split())
il = lambda: list(map(int, input().split()))
ls = lambda: list(input())
let = '@abcdefghijklmnopqrstuvwxyz'
from collections import deque,OrderedDict
gph=[[] for i in range(10**5+10)]
vis=[False for _ in range(10**5+10)]
d=OrderedDict()
it=1
def BFS(sv):
    global d,it,vis
    dq=deque()
    dq.append(sv)
    while len(dq)!=0:
        x=dq[0]
        dq.popleft()
        vis[x]=True
        for i in gph[x]:
            if not vis[i]:
                d[str(x)+','+str(i)]=it%(n-1)
                it+=1
                dq.append(i)
n=ii()
for _ in range(n-1):
    x,y=f()
    d[str(x)+','+str(y)]=-1
    gph[x].append(y)
    gph[y].append(x)
BFS(1)
for i in d:
    print(d[i])