import java.util.*;
import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
public class Solutions {
	 
	static FastScanner scr=new FastScanner();
	static PrintStream out=new PrintStream(System.out);
//	static ArrayList<ArrayList<Integer>>list=new ArrayList<ArrayList<Integer>>();
	public static void main(String []args) {
//		int t=scr.nextInt();
//		while(t-->0) {
			solve();
//		}
	}
	static boolean prime[]=new boolean[2000+1];
	static void solve() {
		int n=scr.nextInt();
		ArrayList<Integer>list[]=new ArrayList[n];
		for(int i=0;i<n;i++) {
			list[i]=new ArrayList<>();
		}
		for(int i=0;i<n-1;i++) {
			int u=scr.nextInt()-1;
			int v=scr.nextInt()-1;
			list[v].add(i);
			list[u].add(i);
		}
		int []label=new int[n];
		Arrays.fill(label,-1);
		boolean found=false;
		for(int i=0;i<n;i++) {
			if(list[i].size()>=3) {
				for(int j=0;j<3;j++) {
					label[list[i].get(j)]=j;
				}
				found=true;
				break;
			}
		}
		if(found) {
			int la=3;
			for(int i=0;i<n-1;i++) {
				if(label[i]==-1) {
					label[i]=la++;
				}
			}
		}else {
			for(int i=0;i<n-1;i++) {
				if(label[i]==-1) {
					label[i]=i;
				}
			}
		}
		for(int i=0;i<n-1;i++) {
			out.println(label[i]+" ");
		}
	}
	static void fill() {
		Arrays.fill(prime,true);
		prime[0]=false;
		prime[1]=false;
		for(int i=2;i<=20000;i++) {
			for(int j=2*i;j<=2000;j+=i) {
				prime[j]=false;
			}
		}
	}
	static void swap(int a[],int i,int j) {
		int temp=a[i];a[i]=a[j];
		a[j]=temp;
	}
	static long modPow(long base,long exp,long mod) {
		if(exp==0) {
			return 1;
		}
		if(exp%2==0) {
			long res=(modPow(base,exp/2,mod));
			return (res*res)%mod;
		}
		return (base*modPow(base,exp-1,mod))%mod;
	}
	static long parse(String s) {
		return Long.parseLong(s);
	}
	static long gcd(long a,long b) {
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int[] sort(int a[]) {
			Arrays.sort(a);
			return a;
		}
		int []reverse(int a[]){
			int b[]=new int[a.length];
			int index=0;
			for(int i=a.length-1;i>=0;i--) {
				b[index]=a[i];
			}
			return b;
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long[] readLongArray(int n) {
			long  [] a=new long  [n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
	static int MAX=Integer.MAX_VALUE;
	static int MIN=Integer.MIN_VALUE;
}class triplet{
	int x;
	int y;
	int z;
	triplet(int fisrt,int second,int third){
		this.x=fisrt;
		this.y=second;
		this.z=third;
	}
}
class pair{
	int x=0;
	int y=0;
	pair(int first,int second){
		this.x=first;
		this.y=second;
	}
}