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>
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.*;
/**
 *
 * @author alanh
 */
public class MEX {
    /*
    public static class ListComparator implements Comparator<List<Integer>> {

        @Override
        public int compare(List<Integer> l1, List<Integer> l2) {
            for (int i = 0; i < l1.size(); ++i) {
                if (l1.get(i).compareTo(l2.get(i)) != 0) {
                    return l1.get(i).compareTo(l2.get(i));
                }
            }
            return 0;
        }        
    }
    */
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String in = sc.nextLine();
        StringTokenizer st = new StringTokenizer(in);
        int T = Integer.parseInt(st.nextToken());
        //System.out.println(T);
        List<List<Integer>> nodes = new ArrayList<>();
        Set<Integer> rootSet = new HashSet<>();
        for(int index =0; index < T-1; index++){
            in = sc.nextLine();
            StringTokenizer ab = new StringTokenizer(in);
            int u = Integer.parseInt(ab.nextToken());
            int v = Integer.parseInt(ab.nextToken());
            
            List<Integer> temp = new ArrayList<>();
            temp.add(u);
            temp.add(v);
            nodes.add(temp);
            
        }               
        //System.out.println(nodes);
        //System.out.println(rootSet);
        //Map<Integer, List<List<Integer>>> tree = new HashMap<>();
        Map<Integer, Integer> roots = new HashMap<>();
        for(int index =0; index < nodes.size(); index++){
            /*
            if(tree.containsKey(nodes.get(index).get(0))){
                List<Integer> temp = new ArrayList<>();
                temp.add(nodes.get(index).get(1));
                tree.get(nodes.get(index).get(0)).add(temp);
            }
            else{
                List<List<Integer>> leafs = new ArrayList<>();
                List<Integer> temp = new ArrayList<>();
                temp.add(nodes.get(index).get(1));
                leafs.add(temp);
                tree.put(nodes.get(index).get(0), leafs);
            }
            if(!tree.containsKey(nodes.get(index).get(1))){
                List<List<Integer>> leafs = new ArrayList<>();
                List<Integer> temp = new ArrayList<>();
                tree.put(nodes.get(index).get(1), leafs);
            }
                    */
            if(roots.containsKey(nodes.get(index).get(0))){
                 
                roots.replace(nodes.get(index).get(0), roots.get(nodes.get(index).get(0))+1);
            }
            else{
                roots.put(nodes.get(index).get(0), 1);
            }
            if(roots.containsKey(nodes.get(index).get(1))){
                roots.replace(nodes.get(index).get(1), roots.get(nodes.get(index).get(1))+1);
            }
            else{
                roots.put(nodes.get(index).get(1), 1);
            }
            
        }  
        //System.out.println(tree);
        //System.out.println(roots);
        
        List<Integer> pair = new ArrayList<>();
        pair.add(0);
        pair.add(0);
        rootSet = roots.keySet();
        List<Integer> rootKeys = new ArrayList<>(rootSet);
        //System.out.println(rootKeys);
        for(int index =0; index < rootKeys.size(); index++){
            if(roots.get(rootKeys.get(index)) > pair.get(1)){
                pair.clear();
                pair.add(rootKeys.get(index));
                pair.add(roots.get(rootKeys.get(index)));
            }
        }
        
        int branches = pair.get(1);
        //System.out.println(branches);
        int start = branches;
        int rootStart =0;
        for(int index =0; index < nodes.size(); index++){
            if(nodes.get(index).get(0).compareTo(pair.get(0)) != 0 && nodes.get(index).get(1).compareTo(pair.get(0)) != 0){
                System.out.println(start);
                start++;
            }
            else if(nodes.get(index).get(0).compareTo(pair.get(0)) == 0 || nodes.get(index).get(1).compareTo(pair.get(0)) == 0){
                System.out.println(rootStart);
                rootStart++;
            }
        }
    }
    
}
