Problem: 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>

Solution (in PYTHON3):

Solution:


"""
NTC here
"""
import sys
inp = sys.stdin.readline
def input(): return inp().strip()
# flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**26)

def iin(): return int(input())


def lin(): return list(map(int, input().split()))


# range = xrange
# input = raw_input

def BFS(s, adj):
    level = []
    parent = {s: None}
    lv = 1
    u = [s]
    while u:  # runs till u is []
        nextu = []
        nx = []
        for i in u:
            for v in adj[i]:
                if v not in parent:
                    parent[v] = i
                    nx.append((i, v))
                    nextu.append(v)
        level.append(nx)
        u = nextu.copy()
    level = level[::-1]
    ans = {}
    ch = 0
    for l in level:
        for p in l:
            ans[p]=ch
            ch+=1
    return ans


def main():
    from collections import defaultdict
    T = 1
    while T:
        T-=1
        n = iin()
        e = [ lin() for i in range(n-1)]
        adj = [set() for i in range(n+1)]
        for i, j in e:
            adj[i].add(j)
            adj[j].add(i)
        # s = 1
        # for i in range(1, n+1):
        #     if len(adj[i])>len(adj[s]):
        #         s = i
        # ans = BFS(s, adj)
        # print(ans)
        # for i, j in e:
        #     print(ans[(i, j)] if (i, j) in ans else ans[(j, i)])
        ch = 0
        ans = {}
        ln = defaultdict(set)
        for i in range(1, n+1):
            l = len(adj[i])
            ln[l].add(i)
        # print(ln)
        while ln[1]:
            a = ln[1]
            ln[1]=set()
            for i in a:
                if not adj[i]:continue
                x, y = i, list(adj[i])[0]
                ans[(x, y)]=ch
                ch+=1
                l = len(adj[y])
                adj[y].remove(x)
                adj[x]=set()
                if l>1:ln[l].remove(y)
                l = len(adj[y])
                if l>0:
                    ln[l].add(y)
            # print(ln, ans)
            # print(adj)
        for i, j in e:
            print(ans[(i, j)] if (i, j) in ans else ans[(j, i)])

main()

# threading.Thread(target=main).start()


"""
1
5
1 3
1 4
1 6
2 6
0 5
"""