import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;


import java.util.Random;
import java.util.TreeSet;

public final class CF_628_D2_C
{


	static boolean verb=true;
	static void log(Object X){if (verb) System.err.println(X);}
	static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
	static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}

	static void logWln(Object X){if (verb) System.err.print(X);}
	static void info(Object o){	System.out.println(o);}
	static void output(Object o){outputWln(""+o+"\n");	}
	static void outputFlush(Object o){try {out.write(""+ o+"\n");out.flush();} catch (Exception e) {}}
	static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}}



	// Global vars
	static BufferedWriter out;
	static InputReader reader;



	static void test() {
		log("testing");

		Random r=new Random();
		int NTESTS=100000;
		int NMAX=10;
		for (int t=0;t<NTESTS;t++) {
		}

		log("done");

	}

	
	static int pgcd(int a,int b) {
		if (a<b)
			return pgcd(b,a);
		while (b>0) {
			int c=b;
			b=a%b;
			a=c;
		}
		return a;
		
	}
	
	static long pgcd(long a,long b) {
		if (a<b)
			return pgcd(b,a);
		while (b>0) {
			long c=b;
			b=a%b;
			a=c;
		}
		return a;
		
	}
	
	static int[] anc;
	static int[] h;
	static int[] stack;
	static int[] how;
	
	static int dfs(ArrayList<Integer>[] friends,ArrayList<Integer>[] edges,int node) {
		int n=friends.length;
		anc=new int[n];
		how=new int[n];
		stack=new int[n];
		
		h=new int[n];
		int st=0;
		stack[st++]=node;
		anc[node]=-1;
		how[node]=-1;
		int max=-1;
		int target=-1;
		while (st>0) {
			int u=stack[st-1];
			st--;
			for (int i=0;i<friends[u].size();i++) {
				int v=friends[u].get(i);
				int e=edges[u].get(i);
				if (v!=anc[u]) {
					anc[v]=u;
					how[v]=e;
					h[v]=h[u]+1;
					stack[st++]=v;
					if (h[v]>max) {
						max=h[v];
						target=v;
					}
				}
			}
		}
		return target;
		
		
	}
	
	static void process() throws Exception {

		//log("hello");

		out = new BufferedWriter(new OutputStreamWriter(System.out));
		reader = new InputReader(System.in);

		int n=reader.readInt();
		ArrayList<Integer>[] friends=new ArrayList[n];
		ArrayList<Integer>[] edges=new ArrayList[n];
		
		for (int i=0;i<n;i++) {
			friends[i]=new ArrayList<Integer>();
			edges[i]=new ArrayList<Integer>();
			
		}
		
		for (int i=0;i<n-1;i++) {
			int u=reader.readInt()-1;
			int v=reader.readInt()-1;
			friends[u].add(v);
			friends[v].add(u);
			edges[u].add(i);
			edges[v].add(i);
		}
		
		int[] res=new int[n-1];
		Arrays.fill(res,-1);
		int end1=dfs(friends,edges,0);
		int end2=dfs(friends,edges,end1);
		int u=end2;
		
		int e=how[u];
		//log("first e:"+e);
		res[e]=0;
		int ref=n-2;
		//log("end1:"+end1+" end2:"+end2);
		while (anc[u]!=end1) {
			
			
			u=anc[u];
			e=how[u];
			
			if (anc[u]==end1) {
				//log("case 1");
				res[e]=1;
			} else {
				//log("case 2");
				res[e]=ref--;
			}
			//log("u:"+u+" e:"+e+" "+res[e]+" "+anc[u]+" "+end1);
		}
		//log(res);
		for (e=0;e<n-1;e++) {
			if (res[e]==-1)
				res[e]=ref--;
			output(res[e]);
		}
		
		
		

		
		
		
	
		try {
			out.close();
		} catch (Exception Ex) {
		}

	}





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

	}

	static final class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.append((char) c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final String readString(int L) throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder(L);
			do {
				res.append((char) c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		public final long readLong() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}

}
/*

5
1 4 5 2 3

 */