import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;


public class DP_6 {

	public static void main(String[] args) throws IOException {
		AlmightyReaderDP_6 rd = new AlmightyReaderDP_6();
		int n = rd.nextInt();
		int a;int b; 
		ArrayList<Integer>[] adj = new ArrayList[n+1];
		for(int i=0;i<n+1;i++) {
			adj[i] = new ArrayList<Integer>();
		}
		int[][] ans = new int[n-1][2];
		for(int i=0;i<n-1;i++) {
			a = rd.nextInt(); b = rd.nextInt();
			ans[i][0]=a; ans[i][1]=b;
			adj[a].add(b);
			adj[b].add(a);
		}
		int j=3;
		int[] z = new int[n-1];
 		for(int i=0;i<n-1;i++) {
			if(z[0]==0  && (adj[ans[i][0]].size()==1 || adj[ans[i][1]].size()==1)) {
				System.out.println(0);
				z[0]=1;
			}
			else if(z[1]==0 && (adj[ans[i][0]].size()==1 || adj[ans[i][1]].size()==1)) {
				System.out.println(1);
				z[1]=1;
			}
			else if(z[2]==0 && z.length>2 && (adj[ans[i][0]].size()==1 || adj[ans[i][1]].size()==1)) {
					System.out.println(2);
					z[2]=1;
				}
			else {
				if(j==n-1) {
					System.out.println(1);
					z[1]=1;
				}
				else {
					System.out.println(j);
					j++;
				}
			}
		}
		
	}
	
	public static void f(ArrayList<Integer>[] adj, int source, boolean[] visited,int[] ans) {
		visited[source] = true;
		if(adj[source].size()==1) {
			
		}
		for(int i=0;i<adj[source].size();i++) {
			if(!visited[adj[source].get(i)]) {
				f(adj, adj[source].get(i),visited,ans);
			}
		}
	}

}
class AlmightyReaderDP_6
{
	BufferedReader br;
	StringTokenizer tk;
	public AlmightyReaderDP_6()
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		tk=new StringTokenizer("");
	}
	public int nextInt() throws IOException
	{
		while(!tk.hasMoreTokens())
			tk=new StringTokenizer(br.readLine());
		return Integer.parseInt(tk.nextToken());
	}
}	
