import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class C {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        ArrayList<Integer>[] edges = new ArrayList[n+1];
        for(int i = 0; i<n+1; i++){
            edges[i] = new ArrayList<>();
        }
        int[] children = new int[n+1];
        int[] order1 = new int[n+1];
        int[] order2 = new int[n+1];
        int[] p = new int[n+1];
        for(int i = 1; i<n; i++){
            StringTokenizer st = new StringTokenizer(br.readLine());
            int a =Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            order1[i] = a;
            order2[i] = b;
            children[a]++;
            edges[a].add(b);
        }
        Deque<Integer> dq = new ArrayDeque<>();
        Deque<Integer> queue = new ArrayDeque<>();
        dq.add(1);
        while(!dq.isEmpty()){
            int current = dq.pollFirst();
            if(children[current]==0){
                queue.add(current);
            }
            for(int a:edges[current]){
                p[a] = current;
                dq.addFirst(a);
            }
        }
        int counter = 1;
        HashMap<Integer,HashMap<Integer,Integer>> map = new HashMap<>();
        for(int i = 0; i<=n; i++){
            map.put(i,new HashMap<>());
        }
        while(!queue.isEmpty()){
            int current = queue.pollFirst();
            children[p[current]]--;
            map.get(p[current]).put(current,counter%(n-1));
            counter++;
            if(children[p[current]]==0){
                queue.addLast(p[current]);
            }
           // System.out.println(current);
        }
        for(int i = 1; i<n; i++){
            System.out.println(map.get(order1[i]).get(order2[i]));
        }
    }
}
