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

public class Solution{
	
	static long mod = 998244353L;
	
	public static void main(String[] args) throws Exception{

		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int n = fs.nextInt();
		int[][] adjList = new int[n-1][2];
		
		int[] count = new int[n+1];
		
		for(int i=0;i<n-1;i++) {
			int u = fs.nextInt(), v =fs.nextInt();
			count[u]++;
			count[v]++;
			adjList[i][0] = u;
			adjList[i][1] = v;
		}
		
		int max = 1;
		for(int i=1;i<=n;i++) {
			if(count[i]>count[max]) max = i;
		}
		
		int n1 = 0;
		int n2 = count[max];
		
		for(int i=0;i<n-1;i++) {
			
			if(adjList[i][0]==max || adjList[i][1]==max) {
				out.println(n1++);
			}
			else {
				out.println(n2++);
			}
		}
		
		
		out.close();
	}
	
	
	
	
	static class FastScanner{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		public String next(){
			while(!st.hasMoreElements()){
				try{
					st = new StringTokenizer(br.readLine());
				} catch(IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		
		public String nextLine() throws IOException {
			return br.readLine();
		}
		
		public int nextInt(){
			return Integer.parseInt(next());
		}

		public int[] readArray(int n){
			int[] a = new int[n];
			for(int i=0;i<n;i++)
				a[i] = nextInt();
			return a;
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
	
}
