/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

 public class Graph 
{ 
	 int V; // No. of vertices 
     LinkedList<Integer> adj[]; //Adjacency Lists 

	// Constructor 
	Graph(int v) 
	{ 
		V = v; 
		adj = new LinkedList[v]; 
		for (int i=0; i<v; ++i) 
			adj[i] = new LinkedList(); 
	} 

	// Function to add an edge into the graph 
	void addEdge(int v,int w) 
	{ 
		adj[v-1].add(w-1); 
	} 

	// prints BFS traversal from a given source s 
	int[][] BFS(int s,int ans[][],int len) 
	{ 
		// Mark all the vertices as not visited(By default 
		// set as false) 
		boolean visited[] = new boolean[V]; 
        int k1=0;
        int k2=len-2;
        boolean flag=false;
		// Create a queue for BFS 
		LinkedList<Integer> queue = new LinkedList<Integer>(); 

		// Mark the current node as visited and enqueue it 
		visited[s]=true; 
		queue.add(s); 

		while (queue.size() != 0) 
		{ 
			// Dequeue a vertex from queue and print it 
			s = queue.poll(); 
			flag=!flag;
			//System.out.print(s+" "); 

			// Get all adjacent vertices of the dequeued vertex s 
			// If a adjacent has not been visited, then mark it 
			// visited and enqueue it 
			Iterator<Integer> i = adj[s].listIterator(); 
			while (i.hasNext()) 
			{ 
				int n = i.next(); 
				if (!visited[n]) 
				{   
				    if(flag==true){
				    ans[s][n]=k1;
                    k1++;
				    }
				    else{
				    ans[s][n]=k2;
                    k2--;
				    }
				    
					visited[n] = true; 
					queue.add(n); 
				} 
			} 
		} 
		return ans;
	} 

	// Driver method to 
	public static void main(String args[]) 
	{ 
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
        int arr[]=new int[n];
        int ans[][]=new int[n][n];
        Graph g = new Graph(n);
        int xarr[]=new int[n-1];
        int yarr[]=new int[n-1];
        for(int i=0;i<n-1;i++){
            int x=sc.nextInt();
            int y=sc.nextInt();
            xarr[i]=x;
            yarr[i]=y;
            arr[y-1]++;
            //System.out.println(x+" "+y);
            g.addEdge(x, y);
        }
        int root=1;
        for(int i=0;i<n;i++){
            if(arr[i]==0){
                //root=i+1;
                root=i;
                break;
            }
        }
        //System.out.println(root);
        
        ans=g.BFS(root,ans,n);
        for(int i=0;i<n-1;i++){
            System.out.println(ans[xarr[i]-1][yarr[i]-1]);
        }

	} 
} 
// This code is contributed by Aakash Hasija 
