import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class C {

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(new BufferedInputStream(System.in, 1 << 11));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out), 1 << 11);
        int n = in.nextInt();
        TreeMap<Integer, Set<Integer>> g = new TreeMap<>();
        int idx = 0;
        Map<List<Integer>, Integer> idxs = new HashMap<>();
        for (int i = 0; i < n - 1; i++) {
            int u = in.nextInt();
            int v = in.nextInt();
            List<Integer> pair = Arrays.asList(u, v);
            pair.sort(Comparator.naturalOrder());
            idxs.put(pair, idx++);
            g.computeIfAbsent(u, HashSet::new).add(v);
            g.computeIfAbsent(v, HashSet::new).add(u);
        }
        Optional<Integer> fork = g.keySet().stream()
                .filter(u -> g.get(u).size() > 2)
                .findAny();
        int c = 0;
        int[] anss = new int[n - 1];
        Arrays.fill(anss, -1);
        if (fork.isPresent()) {
            Integer u = fork.get();
            Iterator<Integer> vs = g.get(u).iterator();
            anss[idxs.get(Stream.of(u, vs.next()).sorted().collect(Collectors.toList()))] = c++;
            anss[idxs.get(Stream.of(u, vs.next()).sorted().collect(Collectors.toList()))] = c++;
            anss[idxs.get(Stream.of(u, vs.next()).sorted().collect(Collectors.toList()))] = c++;
        }
        for (int i = 0; i < anss.length; i++) {
            if (anss[i] == -1) {
                anss[i] = c++;
            }
        }

        for (int i : anss) {
            out.write(i + "\n");
        }
    }
}
