import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);
 
 		int n =fr.nextInt() ,e[][] =new int[n-1][3] ,dg[] =new int[n] ,i ,j =0 ,k =0 ;
 		for (i =1 ; i<n ; ++i) {
 			e[i-1][0] =fr.nextInt()-1 ;	e[i-1][1] =fr.nextInt()-1 ;
 			++dg[e[i-1][0]] ;	++dg[e[i-1][1]] ;
 		}
 		for (i =0 ; i<n ; ++i) {
 			if (dg[i]==1)	++j ;
 		}
 		for (i =0 ; i+1<n ; ++i) {
 			if (dg[e[i][0]]==1 || dg[e[i][1]]==1)	e[i][2] =k++ ;
 			else 	e[i][2] =j++ ;
 		}
 		for (i =0 ; i+1<n ; ++i)	op.println(e[i][2]) ;
		op.flush();	op.close();
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

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

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