/**
 * ******* Created  on 14/3/20 7:50 PM*******
 */

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

public class C1325 implements Runnable {

    private static final int MAX = (int) (1E5 + 5);
    private static final int MOD = (int) (1E9 + 7);
    private static final long Inf = (long) (1E14 + 10);
    private static final double eps = (double) (1E-9);
    List<Pair>[] edges = new List[MAX];
    class Pair{
        int f;
        int s;
        Pair(int a,  int b){
            f =a;
            s=b;
        }
    }
    private void solve() throws IOException {
        int t = 1;

        while (t-- >0){
            int n = reader.nextInt();
            for(int i=0;i<n;i++)
                edges[i] = new ArrayList<Pair>();
            for(int i=0;i<n-1;i++){
                int a = reader.nextInt();a--;
                int b = reader.nextInt();b--;
                edges[a].add(new Pair(b,i));
                edges[b].add(new Pair(a,i));
            }
            dfs(0,-1);
            dfs2(0,-1,0);
            mxv =0;


            Arrays.fill(res,-1);
            for(int i=0;i<n;i++) {
                mxv = Math.max(mxv, mx[i]);

                if(mxv < mx[i]){
                    mxv = mx[i];
                }
            }
            int va =0;
            dfs3(0,-1);

            int r =n-2;
            Arrays.sort(sz, 0, n, new Comparator<Pair>() {
                @Override
                public int compare(Pair o1, Pair o2) {
                    return o1.f-o2.f;
                }
            });

            for(int i=0;i<n;i++){
                int v =sz[i].s;
                for(Pair p : edges[v]){
                 if(res[p.s]==-1){
                     res[p.s]=r;
                     r--;
                 }
                }
            }
            for(int i=0;i<n-1;i++)
                writer.println(res[i]);
        }
    }
    int mxv =0,center =0;
    int[] res = new int[MAX];
    boolean flag =false;
    private void dfs3(int v, int p) {
        if(flag)return;
        for(int i=0;i<edges[v].size() && !flag;i++){
            int u = edges[v].get(i).f;
            int id = edges[v].get(i).s;
            if(mx1[u] == mxv/2){
                center =v;
                flag=true;
                return;
            }
            if(u!=p)
                dfs3(u,v);

        }
    }

    private void dfs2(int v, int p, int sum ) {
        mx[v] = Math.max(mx[v], sum + mx1[v]);
        for(int i =0;i< edges[v].size();i++){
            int u = edges[v].get(i).f;
            int val = (mx1[v] == mx1[u]-1) ? mx2[v]+1: mx1[v]+1;
            if(u!=p)
                dfs2(u,v,Math.max(sum,val));
        }
    }

    int[] mx = new int[MAX];
    int[] mx1 = new int[MAX];
    int[] mx2 = new int[MAX];
    Pair[] sz = new Pair[MAX];
    private int dfs(int v, int p) {
        sz[v]= new Pair(1,v);
        for(int i=0;i<edges[v].size();i++){
            int u =  edges[v].get(i).f;
            int val =0;

            if(u ==p)continue;
            val = dfs(u,v);

            sz[v].f+=sz[u].f;

            if(mx1[v] < val ){
                mx2[v] = mx1[v];
                mx1[v] =val;
            }
            else if(mx2[v] < val)
                mx2[v] = val;
        }
        mx[v] = Math.max(mx[v],mx1[v] + mx2[v]+1);
        return mx1[v]+1;
    }

    public static void main(String[] args) throws IOException {
        try (Input reader = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
            new C1325().run();
        }
    }

    StandardInput reader;
    PrintWriter writer;

    @Override
    public void run() {
        try {
            reader = new StandardInput();
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    interface Input extends Closeable {
        String next() throws IOException;

        default int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        default long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        default double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        default int[] readIntArray() throws IOException {
            return readIntArray(nextInt());
        }

        default int[] readIntArray(int size) throws IOException {
            int[] array = new int[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        default long[] readLongArray(int size) throws IOException {
            long[] array = new long[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextLong();
            }
            return array;
        }
    }

    private static class StandardInput implements Input {
        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        private StringTokenizer stringTokenizer;

        @Override
        public void close() throws IOException {
            reader.close();
        }

        @Override
        public String next() throws IOException {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                stringTokenizer = new StringTokenizer(reader.readLine());
            }
            return stringTokenizer.nextToken();
        }
    }
}
