import java.io.*;
import java.util.*;

public class Main {

    static ArrayList<pair> nodesUnder;
    static boolean[] vis;

    static int dfs(ArrayList<Integer>[] tree, int ver, int par){
        vis[ver] = true;
        int ans = 1;
        if(tree[ver].size() == 1 && vis[tree[ver].get(0)]){
            nodesUnder.add(new pair(ver, ans));
            return ans;
        }
        for(int z: tree[ver]){
            if(z!=par && !vis[z]){
                ans += dfs(tree, z, ver);
            }
        }
        nodesUnder.add(new pair(ver, ans));
        return ans;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        ArrayList<Integer>[] tree = new ArrayList[n];
        for(int i = 0; i<n; i++) tree[i] = new ArrayList<>();
        int[] order = new int[n-1];
        for(int i = 0; i<n-1; i++){
            String[] str = br.readLine().split(" ");
            int u = Integer.parseInt(str[0])-1, v = Integer.parseInt(str[1])-1;
            order[i] = v;
            tree[u].add(v);
            tree[v].add(u);
        }
        nodesUnder = new ArrayList<>();
        vis = new boolean[n];
        Collections.sort(nodesUnder);
        dfs(tree, 0, -1);
        int[] ans = new int[n];
        int num = 0;
        for(pair p: nodesUnder){
            ans[p.id] = num;
            num++;
        }
        for(int z: order){
            System.out.println(ans[z]);
        }
    }

    static class pair implements Comparable<pair>{
        int id, count;
        pair(int a, int b){
            id = a;
            count = b;
        }
        @Override
        public int compareTo(pair p){
            return this.count-p.count;
        }
    }
}