import java.io.*;
import java.util.*;
 
/**
 * Only By Abhi_Valani
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Unstoppable solver = new Unstoppable();
	//	int t=in.nextInt();
	//	while(t-->0)
        solver.solve(in, out);
        out.close();
    }
 
    static class Unstoppable {
   public void solve(InputReader in, PrintWriter out) {
          int n=in.nextInt();
          int count[][]=new int[n+1][2];
        ArrayList<Integer>[] edge=new ArrayList[n+1];
        Arrays.setAll(edge, e-> new ArrayList<Integer>()); 
        int a[][]=new int[n+1][n+1];
        int x[]=new int[n]; int y[]=new int[n];
        for(int i=0;i<n-1;i++){
            x[i]=in.nextInt(); y[i]=in.nextInt();
            count[x[i]][0]=x[i];
            count[x[i]][1]++; 
            count[y[i]][0]=y[i];
            count[y[i]][1]++;
        	edge[x[i]].add(y[i]);
        	edge[y[i]].add(x[i]);
        }        
        Arrays.sort(count,new Comparator<int[]>(){
          public int compare(int a[],int b[]) { return a[1]-b[1]; }   
        });
        int c=0;
        for(int i=0;i<n+1;i++)
        {
            if(count[i][1]!=0)
            {
              for(int j=0;j<edge[count[i][0]].size();j++)
              {   if(a[count[i][0]][edge[count[i][0]].get(j)]!=0) continue;
                  a[count[i][0]][edge[count[i][0]].get(j)]=c; a[edge[count[i][0]].get(j)][count[i][0]]=c; c++; if(c==n-1) break;
                  //out.println(a[count[i][0]][edge[count[i][0]].get(j)]);
              }
            }if(c==n-1) break;
        }
         for(int i=0;i<n-1;i++){
         out.println(a[x[i]][y[i]]);
        }  
        }
 
    }

 
    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 long nextLong(){
            return Long.parseLong(next());
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
    }
}
 