# -*- coding: utf-8 -*-
"""
Created on Tue Apr  7 00:50:53 2020

@author: Mithilesh
"""

n = int(input())
adj = {}
ans = [-1 for i in range(n-1)]
var = 0
for i in range(n-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    if a in adj:
        adj[a].append(b)
    else:
        adj[a] = [b]
    if b in adj:
        adj[b].append(a)
    else:
        adj[b] = [a]

for i in range(n-1):
    if len(adj[i])>2:
        ans[adj[i][0]] = 0
        ans[adj[i][1]] = 1
        ans[adj[i][2]] = 2
        var = 3
        break

for i in range(n-1):
    if ans[i]==-1:
        ans[i]=var
        var+=1

for i in range(n-1):
    print(ans[i])
        