import java.io.*;
import java.util.*;
 
public class Main {

	public static void main(String[] args)throws IOException {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
		int n = in.nextInt();
		int ct[] = new int[n];
		Arrays.fill(ct,0);
		int arr[][] = new int[n-1][3];
		for(int i=0;i<n-1;i++)
		{
			int u = in.nextInt()-1;
			int v = in.nextInt()-1;
			ct[u]++; ct[v]++;
			arr[i][0]=u; arr[i][1]=v; arr[i][2]=-1;
		}
		int lbl=0;
		for(int i=0;i<n-1;i++)
		{
			int u=arr[i][0],v=arr[i][1];
			if(ct[u]==1 || ct[v]==1)
				arr[i][2]=lbl++;
		}
		for(int i=0;i<n-1;i++)
		{
			if(arr[i][2]==-1)
				arr[i][2]=lbl++;
			out.println(arr[i][2]);
		}
        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());
        }

    }

}