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

public class A {

	static BufferedReader br;
	static PrintWriter pw;
	static int inf = (int) 1e9;
	static long mod = (long) 1e9 + 7;

	static boolean[] vis;
	static int[] sta;
	static int[] p;
	static HashSet<Integer> h;
	static ArrayList<Integer>[] g;

	static int n, k;

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		n = Integer.parseInt(st.nextToken());
		g = new ArrayList[n];
		for (int i = 0; i < g.length; i++) {
			g[i] = new ArrayList<>();
		}

		int m = n;
		pair[] a = new pair[n - 1];
		for (int i = 0; i < a.length; i++) {
			st = new StringTokenizer(br.readLine());
			int u = Integer.parseInt(st.nextToken()) - 1;
			int v = Integer.parseInt(st.nextToken()) - 1;
			g[u].add(v);
			g[v].add(u);
			a[i] = new pair(u, v);
		}
		int id = n - 2;
		int[] ans = new int[n - 1];
		for (int i = 0; i < a.length; i++) {
			pair p = a[i];
			if (g[p.x].size() == 1 || g[p.y].size() == 1)
				ans[i] = id--;
		}
		for (int i = 0; i < ans.length; i++) {
			pair p = a[i];
			if (g[p.x].size() == 1 || g[p.y].size() == 1)
				;
			else
				ans[i] = id--;
		}
		for (int i = 0; i < ans.length; i++) {
			pw.println(ans[i]);
		}
		pw.flush();
		pw.close();

	}

	static pair[] val;
	static HashSet<Integer> ans;

	static boolean dfs(int node, int p) {
		vis[node] = true;
		boolean f = true;
		if (g[node].size() == 1 && p != -1) {
			if (h.contains(node)) {
				return true;
			} else {
				ans.add(node + 1);
				return false;
			}
		}
		boolean t = false;
		for (int x : g[node]) {
			if (!vis[x]) {
				t |= dfs(x, node);
				f &= t;
			}
		}
		if (!h.contains(node) && f)
			ans.add(node + 1);
		return t;
	}

	static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int d, int u) {
			x = d;
			y = u;
		}

		public int compareTo(pair o) {
			return x - o.x;
		}

	}

	static class triple implements Comparable<triple> {
		int x;
		int y;
		int z;

		public triple(int a, int b, int c) {
			x = a;
			y = b;
			z = c;
		}

		public int compareTo(triple o) {
			return x - o.x;
		}
	}

	static int[] nxtarr() throws IOException {
		StringTokenizer st = new StringTokenizer(br.readLine());
		int[] a = new int[st.countTokens()];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		return a;
	}

	static long pow(long a, long e) // O(log e)
	{
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res *= a;
			a *= a;
			e >>= 1;
		}
		return res;
	}

	static int gcd(int a, int b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}
}
