from sys import stdin
from collections import deque
mod = 10**9 + 7
import sys
import random
# 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))






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
    hash1[(b,a)] = i+1
    hash[a].append(b)
    hash[b].append(a)

ans = [-1]*(n-1)


boo = defaultdict(bool)
flag = 0
if n>3:
  for i in range(n):
      if len(hash[i]) >= 3:
          a,b,c = hash[i][0],hash[i][1],hash[i][2]
          z1,z2,z3 = hash1[(a,i)],hash1[(b,i)],hash1[(c,i)]

          ans[z1-1] = 0
          ans[z2-1] = 1
          ans[z3-1] = 2
          flag = 1
          break


else:
    for i in range(n-1):
        print(i)
    exit()
# print(ans)
if flag:
 la = [i for i in range(3,n-1)]
else:
    la = [i for i in range(n-1)]

for i in range(n-1):
    if ans[i] == -1:
      # print(i)
      ans[i] = la.pop()
for i in ans:
    print(i)




