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

public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static double a,b;
    static ArrayList<Integer>[] adj;
    static boolean[] visit;
    static int[] ans;
    static long ceildiv(long x, long y){ return (x+y-1)/y;}
    public static void main(String[] args) throws Exception {
        sc= new Scanner(System.in);
        pw=new PrintWriter(System.out);
//        int t=sc.nextInt();
//        while(t-->0){
            int n=sc.nextInt();
            adj=new ArrayList[n];
//            visit= new boolean[n];
            for(int i=0; i<n; i++)
                adj[i]=new ArrayList<Integer>();
            HashMap<Pair, Integer> map= new HashMap<Pair, Integer>();
            ArrayList<Pair> list= new ArrayList<Pair>();
            for(int i=1; i<n; i++){
                int x=sc.nextInt()-1, y=sc.nextInt()-1;
                adj[x].add(y); adj[y].add(x);
                Pair p=new Pair(x, y);
                map.put(p, -1);
                list.add(p);
            }
            TreeSet<Integer> tree= new TreeSet<Integer>();
            for(int i=0; i<n-1; i++)
                tree.add(i);
            for(int i=0; i<n; i++){
                if(adj[i].size()>=3){
                    int j=0;
                    for(int x: adj[i]){
                        if(j==3)
                            break;
                        Pair p1= new Pair(i, x), p2= new Pair(x, i);
                        if(map.containsKey(p1))
                            map.replace(p1, j);
                        else
                            map.replace(p2, j);
                        tree.remove(j++);
                    }
                    break;
                }
            }
            for(Pair p: list){
                if(map.get(p)!=-1)
                    pw.println(map.get(p));
                else
                    pw.println(tree.pollFirst());
            }
//        }
        pw.close();
    }
    static void printArr(int[] arr){
        for(int i=0; i<arr.length-1; i++)
            pw.print(arr[i]+" ");
        pw.println(arr[arr.length-1]);
    }
    static void printArr(long[] arr){
        for(int i=0; i<arr.length-1; i++)
            pw.print(arr[i]+" ");
        pw.println(arr[arr.length-1]);
    }
    static void printArr(Integer[] arr){
        for(int i=0; i<arr.length-1; i++)
            pw.print(arr[i]+" ");
        pw.println(arr[arr.length-1]);
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n, int l) throws IOException{
            Pair[] arr=new Pair[n];
            if(l==2){
                int[] a=nextArr(n), b=nextArr(n);
                for(int i=0; i<n; i++)
                    arr[i]=new Pair(a[i], b[i]);
                return arr;
            }
            for(int i=0; i<n; i++)
                arr[i]=new Pair(nextInt(), nextInt());
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return this.x*1000+this.y;
        }
        public int compareTo(Pair other) {
            if(this.y!=other.y)
                return this.y-other.y;
            return this.x-other.x;
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            if(this.x==p.x)
                return this.y==p.y;
            if(this.x==p.y)
                return this.y==p.x;
            else
                return false;
        }
        public boolean equal(Pair p){
            if(this.x==p.x)
                return this.y==p.y;
            if(this.x==p.y)
                return this.y==p.x;
            else
                return false;
        }
    }
}
