/*
[ ( ^ _ ^ ) ]
*/

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


public class test {
    int INF = (int)1e9;
    long MOD = 1000000007;
    
    int n;
    ArrayList<ArrayList<Integer>> g;
    int[][] e;
    boolean[] vis;
    int x;

    boolean go(int v) {
        if(vis[v]) return false;
        vis[v] = true;
        int a = g.get(v).size();
        // show("x", x);
        if(x==1) {
            int i = 0;
            for(; i<a; i++) {
                int u = g.get(v).get(i);
                e[u>=n?u-n:u][2] = x; ++x;
                // show("put", 1, v, e[u][1]);
                if(go(e[u][1])) return true;
                break;
            }
            for(; i<a; i++) {
                int u = g.get(v).get(i);
                if(go(e[u][1])) return true;
            }
        } else {
            if(a>=2) {
                int c = 0;
                for(int i: g.get(v)) {
                    int u = e[i][1];
                    if(!vis[u]) {
                        c++;
                        if(c>=2) {
                            break;
                        }
                    }
                }
                if(c<2) {
                    return false;
                }
                for(int i: g.get(v)) {
                    int u = e[i][1];
                    if(!vis[u]) {
                        e[i>=n?i-n:i][2] = x++;
                        // show("put", x-1, v, e[i][1]);
                        if(x==4) {
                            break;
                        }
                    }
                }
                return true;
            } else {
                for(int i: g.get(v)) {
                    if(go(e[i][1])) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    void solve(InputReader in, PrintWriter out) throws IOException {
        n = in.nextInt();
        e = new int[2*n][3];
        g = new ArrayList<>();
        for(int i=0; i<n; i++) {
            g.add(new ArrayList<Integer>());
            // show(i, g);
        }
        // show("");
        // show(g);
        for(int i=0; i<n-1; i++) {
            e[i][0] = in.nextInt()-1;
            e[i][1] = in.nextInt()-1;
            e[n+i][0] = e[i][1];
            e[n+i][1] = e[i][0];
            g.get(e[i][0]).add(i);
            g.get(e[i][1]).add(n+i);
        }
        // show("", e);
        // show("", g);
        x = 1;
        vis = new boolean[n];
        go(0);
        // show("", e);
        for(int i=0; i<n-1; i++) {
            if(e[i][2]==0) {
                out.println((x++)-1);
            } else {
                out.println(e[i][2]-1);
            }
        }
    }
    
    
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        while(t-- >0) {
            new test().solve(in, out);
        }
        out.close();
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}