import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class Main {
    static List<Integer> al[];
    private static void solver(InputReader sc, PrintWriter out) {
        int n = sc.nextInt();
        al = new ArrayList[n];
        for(int i=0; i<n; i++) al[i] = new ArrayList<>();
        List<Pair> list = new ArrayList<>();
        Map<Pair,Integer> hm = new LinkedHashMap<>();
        for(int i=0; i<n-1; i++){
            int x = sc.nextInt()-1;
            int y = sc.nextInt()-1;
            al[x].add(y);
            al[y].add(x);
            Pair p = new Pair(x,y);
            list.add(p);
            hm.put(p,-1);
        }
        int count=0;
        for(Pair p : list){
            if(al[p.x].size()==1 || al[p.y].size()==1){
                hm.put(p,count); count++;
            }
        }
        for(Map.Entry<Pair,Integer> map : hm.entrySet()){
            int y = map.getValue();
            if(y==-1){
                out.println(count); count++;
            }
            else
                out.println(y);
        }

    }
    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int[] readIntArray(int n){
            int arr[] = new int[n];
            for(int i=0;i<n;i++) arr[i] = nextInt();
            return arr;
        }
    }
}
class Pair{
    int x,y;
    Pair(int x, int y){
        this.x = x;
        this.y = y;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Pair pair = (Pair) o;
        return x == pair.x &&
                y == pair.y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }
}