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

public class C {
	
	public static boolean DEBUG = true;
	
    public static void main(String[] args) throws IOException {
    	FastScanner scan;
    	PrintWriter out;
    	if (DEBUG) {
    		scan = new FastScanner();
        	out = new PrintWriter(System.out);
    	}
    	else {
        	scan = new FastScanner("test.in");
        	out = new PrintWriter(new BufferedWriter(new FileWriter("test.out")));
    	}
        
        int N = scan.nextInt();

        ArrayList<Integer>[] graph = (ArrayList<Integer>[])new ArrayList[N];
        for(int i=0; i<N; i++) {
            graph[i] = new ArrayList<Integer>();
        }

        for(int i=0; i<N-1; i++) {
            int a = scan.nextInt()-1;
            int b = scan.nextInt()-1;

            graph[a].add(i);
            graph[b].add(i);
        }

        int[] arr = new int[N-1];
        Arrays.fill(arr,-1);

        int j = 0;

        for(int i=0; i<N; i++) {
            if(graph[i].size() <= 2) continue;

            for(j=0; j<graph[i].size(); j++) {
                arr[graph[i].get(j)] = j;
            }
            break;
        }

        for(int i=0; i<N-1; i++) {
            if(arr[i] == -1) {
                arr[i] = j++;
            }
        }

        for(int i=0; i<N-1; i++) {
            System.out.println(arr[i]);
        }
        
        
        out.close();
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}