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

public class feb20 {

//	            ***                          ++                      
//             +=-==+                      +++=-                     
//            +-:---==+                   *+=----=                   
//           +-:------==+               ++=------==                  
//           =-----------=++=========================                
//          +--:::::---:-----============-=======+++====             
//          +---:..:----::-===============-======+++++++++           
//          =---:...---:-===================---===++++++++++         
//          +----:...:-=======================--==+++++++++++        
//          +-:------====================++===---==++++===+++++      
//         +=-----======================+++++==---==+==-::=++**+     
//        +=-----================---=======++=========::.:-+*****    
//       +==::-====================--:  --:-====++=+===:..-=+*****   
//       +=---=====================-...  :=..:-=+++++++++===++*****  
//       +=---=====+=++++++++++++++++=-:::::-====+++++++++++++*****+ 
//      +=======++++++++++++=+++++++============++++++=======+****** 
//      +=====+++++++++++++++++++++++++==++++==++++++=:...  . .+**** 
//     ++====++++++++++++++++++++++++++++++++++++++++-.     ..-+**** 
//     +======++++++++++++++++++++++++++++++++===+====:.    ..:=++++ 
//     +===--=====+++++++++++++++++++++++++++=========-::....::-=++* 
//     ====--==========+++++++==+++===++++===========--:::....:=++*  
//     ====---===++++=====++++++==+++=======-::--===-:.  ....:-+++   
//     ==--=--====++++++++==+++++++++++======--::::...::::::-=+++    
//     ===----===++++++++++++++++++++============--=-==----==+++     
//     =--------====++++++++++++++++=====================+++++++     
//     =---------=======++++++++====+++=================++++++++     
//     -----------========+++++++++++++++=================+++++++    
//     =----------==========++++++++++=====================++++++++  
//     =====------==============+++++++===================+++==+++++ 
//     =======------==========================================++++++

	// created by : Nitesh Gupta

	public static void main(String[] args) throws Exception {

//		first();
//		sec();
		third();
//			four();
//			fif();
//			six();
	}

	private static void first() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] scn = (br.readLine()).trim().split(" ");
		StringBuilder sb = new StringBuilder();

		int n = Integer.parseInt(scn[0]);
		String str = br.readLine();

		ArrayList<Character> list = new ArrayList<>();
		for (int i = 0; i < n; i++)
			list.add(str.charAt(i));

		for (char ch = 'z'; ch >= 'a'; ch--) {
			boolean[] vis = new boolean[list.size()];
			boolean repeat = false;
			for (int j = 0; j < list.size() - 1; j++) {
				char curr = list.get(j).charValue();
				char next = list.get(j + 1).charValue();
				if (curr == ch && curr - 1 == next) {
					vis[j] = true;
					repeat = true;
				}

			}
			for (int j = 1; j < list.size(); j++) {
				char curr = list.get(j).charValue();
				char next = list.get(j - 1).charValue();
				if (curr == ch && curr - 1 == next) {
					vis[j] = true;
					repeat = true;
				}

			}
			ArrayList<Character> child = new ArrayList<>();
			for (int j = 0; j < list.size(); j++) {
				if (!vis[j]) {
					child.add(list.get(j));
				}
			}
			list = child;
			if (repeat) {
				ch++;
			}

		}
		System.out.println(n - list.size());
		return;
	}

	private static void sec() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] scn = (br.readLine()).trim().split(" ");
		StringBuilder sb = new StringBuilder();
		long u = Long.parseLong(scn[0]);
		long v = Long.parseLong(scn[1]);
		if (u > v || u % 2 != v % 2) {
			sb.append("-1");
		} else {
			if (u == v) {
				if (u == 0) {
					sb.append("0");
				} else {
					sb.append("1\n" + u);
				}
			} else {
				long x = (v - u) / 2;
				if ((u & x) == 0) {
					sb.append("2\n" + (u + x) + " " + x);
				} else {
					sb.append("3\n" + u + " " + x + " " + x);
				}
			}
		}
		sb.append("\n");
		System.out.println(sb);
		return;
	}

	private static void third() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] scn = (br.readLine()).trim().split(" ");
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(scn[0]);
		ArrayList<ArrayList<Integer>> list = new ArrayList<>();
		for (int i = 0; i <= n; i++) {
			list.add(new ArrayList<>());
		}

		ArrayList<Integer> inp = new ArrayList<>();
		for (int i = 0; i < n - 1; i++) {
			scn = (br.readLine()).trim().split(" ");
			int u = (int) Long.parseLong(scn[0]);
			int v = (int) Long.parseLong(scn[1]);
			list.get(u).add(v);
			list.get(v).add(u);
			inp.add(u);
			inp.add(v);
		}
		ArrayList<HashMap<Integer, Integer>> ans = new ArrayList<>();
		for (int i = 0; i <= n; i++) {
			ans.add(new HashMap<>());
		}
		dfs(list, -1, 1, new boolean[n + 1], ans);
		for (int i = 0; i < inp.size(); i += 2) {
			int u = inp.get(i);
			int v = inp.get(i + 1);
			if (ans.get(u).containsKey(v)) {
				sb.append(ans.get(u).get(v));
			} else {
				sb.append(ans.get(v).get(u));
			}
			sb.append("\n");
		}
		System.out.println(sb);
		return;
	}

	static int num = 0;
	static boolean changed = false; 

	private static void dfs(ArrayList<ArrayList<Integer>> list,int par, int src, boolean[] vis,
			ArrayList<HashMap<Integer, Integer>> ans) {
		vis[src] = true;
		boolean leaf = true;
		for (int nn : list.get(src)) {
			if (!vis[nn]) {
				leaf = false;
				ans.get(src).put(nn, num);
				ans.get(nn).put(src, num);
				num += 1;
				if (num == 1)
					num += 1;
				dfs(list,src, nn, vis, ans);

			}
		}
		if(leaf &&!changed && num!=2) { 	
			ans.get(src).put(par, 1);
			ans.get(par).put(src, 1);
			num-=1;
			changed = true;
		}
	}

	private static void four() throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] scn = (br.readLine()).trim().split(" ");
		int t = Integer.parseInt(scn[0]);
		StringBuilder sb = new StringBuilder();

		while (t-- > 0) {
			scn = (br.readLine()).trim().split(" ");
			int n = Integer.parseInt(scn[0]);
			long[] arr = new long[n];
			scn = (br.readLine()).trim().split(" ");
			for (int i = 0; i < n; i++) {
				arr[i] = Long.parseLong(scn[i]);
			}

			sb.append("\n");
		}
		System.out.println(sb);
		return;
	}

	private static void fif() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] scn = (br.readLine()).trim().split(" ");
		int t = Integer.parseInt(scn[0]);
		StringBuilder sb = new StringBuilder();

		while (t-- > 0) {
			scn = (br.readLine()).trim().split(" ");
			int n = Integer.parseInt(scn[0]);
			long[] arr = new long[n];
			scn = (br.readLine()).trim().split(" ");
			for (int i = 0; i < n; i++) {
				arr[i] = Long.parseLong(scn[i]);
			}

			sb.append("\n");
		}
		System.out.println(sb);
		return;
	}

	private static void six() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] scn = (br.readLine()).trim().split(" ");
		int t = Integer.parseInt(scn[0]);
		StringBuilder sb = new StringBuilder();

		while (t-- > 0) {
			scn = (br.readLine()).trim().split(" ");
			int n = Integer.parseInt(scn[0]);
			long[] arr = new long[n];
			scn = (br.readLine()).trim().split(" ");
			for (int i = 0; i < n; i++) {
				arr[i] = Long.parseLong(scn[i]);
			}

			sb.append("\n");
		}
		System.out.println(sb);
		return;
	}

	public static void sort(long[] arr) {
		int n = arr.length;
		for (int i = 0; i < n; i++) {
			int idx = (int) Math.random() * n;
			long temp = arr[i];
			arr[i] = arr[idx];
			arr[idx] = temp;
		}
		Arrays.sort(arr);
	}

	public static void print(long[][] dp) {
		for (long[] a : dp) {
			for (long ele : a) {
				System.out.print(ele + " ");
			}
			System.out.println();
		}
	}

}
