
import java.io.*;
import java.util.*;
	
public class C 
{	
	
	static ArrayList<Integer> g[];
	static int subtreeSize[],vis[];
	
	public static void main(String[] args)throws IOException 
	{	
		FastReader f=new FastReader();
		StringBuffer sb = new StringBuffer();
		
		int n=f.nextInt();
		
		g=new ArrayList[n+1];
		subtreeSize=new int[n+1];
		vis=new int[n+1];
		
		for(int i=0;i<=n;i++)
		{
			g[i]=new ArrayList<Integer>();
			subtreeSize[i]=1;
		}
		int arr[][]=new int[n+1][2];
		for(int i=1;i<n;i++)
		{
			int x=f.nextInt();
			int y=f.nextInt();
			arr[i][0]=x;
			arr[i][1]=y;
			
			g[x].add(y);
			g[y].add(x);
			
		}
		dfs(1);
//		for(int i=1;i<=n;i++)
//			System.out.print(subtreeSize[i]+" ");
//		System.out.println();
		int max=0;
		int x=0,y=1;
		for(int i=2;i<=n;i++)
		{
			if(subtreeSize[i]>max)
			{
				max=subtreeSize[i];
				x=i;
			}
		}
		int count=1;
		for(int i=1;i<n;i++)
		{
			if((arr[i][0]==x && arr[i][1]==y) || (arr[i][0]==y && arr[i][1]==x))
				sb.append(0+"\n");
			else
				sb.append((count++)+"\n");
		}
		System.out.println(sb);
		
	}
	
	static void dfs(int n)
	{
		vis[n]=1;
		int ttl=0;
		for(int child:g[n])
		{
			if(vis[child]==1)
				continue;
			dfs(child);
			ttl+=subtreeSize[child];
		}
		subtreeSize[n]+=ttl;
	}

	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(); 
	    } 
	    int nextInt() { 
	        return Integer.parseInt(next()); 
	    } 
	    long nextLong() { 
	        return Long.parseLong(next()); 
	    } 
	    double nextDouble() { 
	        return Double.parseDouble(next()); 
	    } 
	    String nextLine() { 
	        String str = ""; 
	        try{ 
	            str = br.readLine(); 
	        } 
	        catch (IOException e) { 
	            e.printStackTrace(); 
	        } 
	        return str; 
	    } 
	}
}