import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.io.DataInputStream; 
import java.io.FileInputStream; 
import java.io.IOException;
import java.io.PrintWriter;


public class R629_C {
    public static void main(String[] args) throws IOException{

        PrintWriter out = new PrintWriter(System.out);
        Reader in = new Reader();
        int n = in.nextInt();
        int[] from = new int[n - 1];
        int[] to = new int[n - 1];
        int[] idxNum = new int[n - 1];
        
        if(n == 2){
            out.println(0);
            out.flush();
            return;
        }
        
        for (int i = 0; i < n - 1; i ++) {
            from[i] = in.nextInt() - 1;
            to[i] = in.nextInt() - 1;
            idxNum[i] = i;
        }
        in.close();
        int[][][] g = createG(from, to, idxNum, n);
        List<Integer> ls = new ArrayList<>();
        
        for(int i = 0; i < n; i++) {
            if (g[i].length == 1)
                ls.add(i);
        }
        int[] ans = new int[n - 1];
        Arrays.fill(ans, -1);
        if (ls.size() >= 3) {
            ans[g[ls.get(0)][0][1]] = 0;
            ans[g[ls.get(1)][0][1]] = 1;
            ans[g[ls.get(2)][0][1]] = 2;
            int gen = 3;
            for (int i = 0; i < n - 1; i++) {
                if (ans[i] == -1)
                    ans[i] = gen++;
            }
        } else {
            int gen = 0;
            for (int i = 0; i < n - 1; i++) {
                    ans[i] = gen++;
            }
        }
        for (int a : ans) {
            out.println(a);
        }
        out.flush();
    }
    private static int[][][] createG(int[] from, int[] to, int[] idxNum, int n) { //uwi
        int[][][] g = new int[n][][];
        int[] p = new int[n];
        
        for (int f : from)
            p[f]++;
        for (int t : to)
            p[t]++;
        
        for (int i = 0; i < n; i++) {
            g[i] = new int[p[i]][2];
        }
        
        for (int i = 0; i < n - 1; i++) {
            --p[from[i]];
            g[from[i]][p[from[i]]][0] = to[i];
            g[from[i]][p[from[i]]][1] = idxNum[i];
            --p[to[i]];
            g[to[i]][p[to[i]]][0] = from[i];
            g[to[i]][p[to[i]]][1] = idxNum[i];
        }
        
        return g;
    }
    
    
    
    static class Reader 
    { 
        final private int BUFFER_SIZE = 1 << 16; 
        private DataInputStream din; 
        private byte[] buffer; 
        private int bufferPointer, bytesRead; 
  
        public Reader() 
        { 
            din = new DataInputStream(System.in); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
  
        public Reader(String file_name) throws IOException 
        { 
            din = new DataInputStream(new FileInputStream(file_name)); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
  
        public String readLine() throws IOException 
        { 
            byte[] buf = new byte[64]; // line length 
            int cnt = 0, c; 
            while ((c = read()) != -1) 
            { 
                if (c == '\n') 
                    break; 
                buf[cnt++] = (byte) c; 
            } 
            return new String(buf, 0, cnt); 
        } 
  
        public int nextInt() throws IOException 
        { 
            int ret = 0; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
            do
            { 
                ret = ret * 10 + c - '0'; 
            }  while ((c = read()) >= '0' && c <= '9'); 
  
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        public long nextLong() throws IOException 
        { 
            long ret = 0; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
            do { 
                ret = ret * 10 + c - '0'; 
            } 
            while ((c = read()) >= '0' && c <= '9'); 
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        public double nextDouble() throws IOException 
        { 
            double ret = 0, div = 1; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
  
            do { 
                ret = ret * 10 + c - '0'; 
            } 
            while ((c = read()) >= '0' && c <= '9'); 
  
            if (c == '.') 
            { 
                while ((c = read()) >= '0' && c <= '9') 
                { 
                    ret += (c - '0') / (div *= 10); 
                } 
            } 
  
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        private void fillBuffer() throws IOException 
        { 
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
            if (bytesRead == -1) 
                buffer[0] = -1; 
        } 
  
        private byte read() throws IOException 
        { 
            if (bufferPointer == bytesRead) 
                fillBuffer(); 
            return buffer[bufferPointer++]; 
        } 
  
        public void close() throws IOException 
        { 
            if (din == null) 
                return; 
            din.close(); 
        } 
    } 
}
