You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such that the following conditions hold:

  * Every label is an integer between 0 and n-2 inclusive. 
  * All the written labels are distinct. 
  * The largest value among MEX(u,v) over all pairs of nodes (u,v) is as small as possible. 



Here, MEX(u,v) denotes the smallest non-negative integer that isn't written on any edge on the unique simple path from node u to node v.

Input

The first line contains the integer n (2 ≤ n ≤ 10^5) — the number of nodes in the tree.

Each of the next n-1 lines contains two space-separated integers u and v (1 ≤ u,v ≤ n) that mean there's an edge between nodes u and v. It's guaranteed that the given graph is a tree.

Output

Output n-1 integers. The i^{th} of them will be the number written on the i^{th} edge (in the input order).

Examples

Input


3
1 2
1 3


Output


0
1


Input


6
1 2
1 3
2 4
2 5
5 6


Output


0
3
2
4
1

Note

The tree from the second sample:

<image>
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)




