import java.util.*;
import java.io.*;
public class B{
	public static void main(String[] args)
	{
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = fs.nextInt();
		Map<String,Integer> hm = new HashMap();
		List<Integer>[] adj = new ArrayList[n+1];
		for(int i=1;i<=n;i++)adj[i] = new ArrayList();
		for(int i=0;i<n-1;i++)
		{
			int u = fs.nextInt(); int v = fs.nextInt();
			String fwd = ""+u+" "+v;
			String rev = ""+v+" "+u;
			hm.put(fwd,i);
			hm.put(rev,i);
			adj[u].add(v);
			adj[v].add(u);
		}
		int[] ans = new int[n-1];
		int[] vis = new int[n+1];
		vis[1] = 1;
		Deque<Integer> q = new ArrayDeque();
		q.add(1);
		int start = 0;
		while(!q.isEmpty())
		{
			int node = q.poll();
			for(int i:adj[node])
			{
				if(vis[i] == 1)continue;
				vis[i] = 1;
				q.add(i);
				String str = ""+node+" "+i;
				int idx = hm.get(str);
				ans[idx] = start;
				start++;
			}
		}
		for(int i=0;i<n-1;i++)
		{
			out.println(ans[i]);
		}
		out.close();
	}
	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 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 nextLong() {
			return Long.parseLong(next());
		}
	}
	public static int[] sort(int[] arr)
	{
		List<Integer> temp = new ArrayList();
		for(int i:arr)temp.add(i);
		Collections.sort(temp);
		int start = 0;
		for(int i:temp)arr[start++]=i;
		return arr;
	}
	public static String rev(String str)
	{
		char[] arr = str.toCharArray();
		char[] ret = new char[arr.length];
		int start = arr.length-1;
		for(char i:arr)ret[start--] = i;
		String ret1 = "";
		for(char ch:ret)ret1+=ch;
		return ret1;
//		return ret;
	}
}