import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;

public class TaskC {
	public static void main(String[] arg) {
		final FastScanner in = new FastScanner(System.in);
		final PrintWriter out = new PrintWriter(System.out);
		final int n = in.nextInt();
		int[][] a = new int[n-1][4];
		Map<Integer,ArrayList<int[]>> map = new HashMap<Integer, ArrayList<int[]>>();
		for(int i=0;i<=n;i++) {
			map.put(i, new ArrayList<int[]>());
		}
		for (int i = 0; i < n-1; i++) {
			a[i][0] = i;
			a[i][1] = in.nextInt();
			a[i][2] = in.nextInt();
			a[i][3] = -1;
			map.get(a[i][1]).add(a[i]);
			map.get(a[i][2]).add(a[i]);
		}
		
	    int [][] g = new int[n+1][2];
	    for(int i=1;i<=n;i++) {
	    	g[i][0]=i;
	    	g[i][1]=map.get(i).size();
	    }
	    
	    Arrays.sort(g, (el1, el2) -> el1[1]-el2[1]);
	    int cnt = 0;
	    for(int i=0; i<=n; i++) {
	    	int node = g[i][0];
	    	Iterator<int[]> edges =map.get(node).iterator();
	    	while(edges.hasNext()) {
	    		int[] edge = edges.next();
	    		if(edge[3]<0) {
	    			edge[3]=cnt;
	    			cnt++;
	    		}
	    	}
	    }
	    for(int i=0;i<a.length;i++) {
	    	out.printf("%d%n", a[i][3]);
	    }
		out.close();
		in.close();
	}


	private static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(InputStream stream) {
			try {
				br = new BufferedReader(new InputStreamReader(stream));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

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

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

		int[] readIntArr(int n) {
			int[] result = new int[n];
			for (int i = 0; i < n; i++) {
				result[i] = Integer.parseInt(next());
			}
			return result;
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

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

	}

}
