from sys import stdin
from collections import deque
mod = 10**9 + 7
import sys
# sys.setrecursionlimit(10**6)
from queue import PriorityQueue
# def rl():
#     return [int(w) for w in stdin.readline().split()]
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt,factorial,gcd,log2,inf,ceil
# map(int,input().split())
# # l = list(map(int,input().split()))
# from itertools import permutations
import heapq
# input = lambda: sys.stdin.readline().rstrip()
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(x, y):
    return f(x) // (f(y) * f(x - y))

# t = int(input())
#
# for _ in range(t):
#
#
#     n = int(input())
#
#     l = list(map(int,input().split()))
#
#     print(len(set(l)))

# t = int(input())
#
# for _ in range(t):
#
#     n = int(input())
#     if n == 2:
#         print(1,1)
#     elif n%2 == 0:
#         print(2,n-2)
#
#     else:
#         print(1,n-1)

def dfs(n):

    boo[n] = True

    for i in hash[n]:

        if not boo[i]:
            if hash1[(n,i)]:
                z = hash1[(n,i)]
                if la1:
                    k = la1.pop()
                    ans[z-1] = k
                else:
                    k = la2.pop()
                    ans[z-1] = k
            else:
               z = hash1[(i,n)]
               if la1:
                  k = la1.pop()
                  ans[z-1] = k
               else:
                  k = la2.pop()
                  ans[z-1] = k
            dfs(i)



n = int(input())

hash = defaultdict(list)
ba = set()
hash1 = defaultdict(int)
for i in range(n-1):
    a,b = map(int,input().split())
    hash1[(a,b)] = i+1
    hash[a].append(b)
    hash[b].append(a)

ans = [0]*(n-1)

la1 = []
la2 = []

for i in range(n-1):
    if i%2 == 0:
        la1.append(i)
    else:
        la2.append(i)
boo = defaultdict(bool)

dfs(1)

for i in ans:
    print(i)






