import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

public class C {

	static Set<Integer> crossroads = new HashSet<>();
	static int[][] edgeColor;

	static class Graph {
		int V;

		LinkedList<Integer> adjListArray[];

		Graph(int V) {
			this.V = V;
			adjListArray = new LinkedList[V];
			edgeColor = new int[V][V];

			for (int i = 0; i < V; i++) {
				adjListArray[i] = new LinkedList<>();
			}
		}
	}

	static void addEdge(Graph graph, int src, int dest) {

		graph.adjListArray[src].add(dest);
		graph.adjListArray[dest].add(src);

		if (graph.adjListArray[src].size() >= 3)
			crossroads.add(src);
		if (graph.adjListArray[dest].size() >= 3)
			crossroads.add(dest);

	}

	static LinkedList<Integer> neigh(Graph g, int i) {
		return g.adjListArray[i];
	}

	static void solve(Graph g, int[][] inputs) {

	}

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);

		int nodes = in.nextInt();
		Graph g = new Graph(nodes);
		int u, v;
		int[][] inputs = new int[nodes - 1][2];
		for (int i = 0; i < nodes - 1; i++) {
			u = in.nextInt();
			v = in.nextInt();
			inputs[i][0] = u - 1;
			inputs[i][1] = v - 1;
			addEdge(g, inputs[i][0], inputs[i][1]);

		}

		int counter = 1;
		for (Integer i : crossroads) {
			for (Integer j : neigh(g, i)) {
				if (edgeColor[i.intValue()][j.intValue()] == 0) {
					edgeColor[i.intValue()][j.intValue()] = counter;
					counter++;
				}
			}
		}
		if (crossroads.isEmpty())
			counter++;
		
		for (int i = 0; i < nodes - 1; i++) {
			if (edgeColor[inputs[i][0]][inputs[i][1]] == 0) {
				out.println(counter - 2);
				counter++;
				out.flush();
			} else {
				out.println(edgeColor[inputs[i][0]][inputs[i][1]] - 2);
				out.flush();

			}
		}

		out.close();
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 64000);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}