
// import java.util.Vector;
import java.util.*;
import java.lang.Math;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import javax.management.Query;
import java.io.*;
import java.math.BigInteger;
import java.io.FileWriter;

public class Main {
    static int mod = 1000000007;

    static class Edge {
        int to;
        long time, k;

        public Edge(int to, long time, long k) {
            this.to = to;
            this.time = time;
            this.k = k;
        }
    }

    static class Pair implements Comparator<Pair> {
        long x;
        long y;

        // Constructor
        public Pair(long x, long y) {
            this.x = x;
            this.y = y;
        }

        public Pair() {
        }

        @Override
        public int compare(Main.Pair o1, Main.Pair o2) {
            if (o1.y < o2.y)
                return -1;
            if (o1.y > o2.y)
                return 1;
            return 0;
        }
    }

    // class to define user defined conparator
    static class Compare implements Comparator<Pair> {

        public int compare(Pair p1, Pair p2) {
            if (p1.x == p2.x) {
                if (p1.y > p2.y) {
                    return 1;
                } else if (p1.y == p2.y) {
                    return 0;
                } else {
                    return -1;
                }
            }
            if (p1.x > p2.x)
                return 1;
            else
                return -1;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                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());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] intArr(int n) {
            int res[] = new int[n];
            for (int i = 0; i < n; i++)
                res[i] = nextInt();
            return res;
        }

        long[] longArr(int n) {
            long res[] = new long[n];
            for (int i = 0; i < n; i++)
                res[i] = nextLong();
            return res;
        }
    }

    static FastReader f = new FastReader();

    static boolean isPrime(long n) {
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;
        if (n % 2 == 0 || n % 3 == 0)
            return false;
        for (long i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;
        return true;
    }

    static int LowerBound(int a[], int x) { // smallest index having value >= x
        int l = -1, r = a.length;
        while (l + 1 < r) {
            int m = (l + r) >>> 1;
            if (a[m] >= x)
                r = m;
            else
                l = m;
        }
        return r;
    }

    static int UpperBound(int a[], int x) {// biggest index having value <= x
        int l = -1, r = a.length;
        while (l + 1 < r) {
            int m = (l + r) >>> 1;
            if (a[m] <= x)
                l = m;
            else
                r = m;
        }
        return l + 1;
    }

    static long gcd(long a, long b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    static long lcm(long a, long b) {
        return (a * b) / gcd(a, b);
    }

    static long power(long x, long y, long p) {
        long res = 1;
        x = x % p;
        while (y > 0) {
            if (y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1; // y = y/2
            x = (x * x) % p;
        }
        return res;
    }

    static long power(long x, long y) {
        long res = 1;
        while (y > 0) {
            if (y % 2 == 1)
                res = (res * x);
            y >>= 1;
            x = (x * x);
        }
        return res;
    }

    static int power(int x, int y) {
        int res = 1;
        while (y > 0) {
            if (y % 2 == 1)
                res = (res * x);
            y >>= 1;
            x = (x * x);
        }
        return res;
    }

    static int ceil(int x, int y) {
        return (x % y == 0 ? x / y : (x / y + 1));
    }

    static long ceil(long x, long y) {
        return (x % y == 0 ? x / y : (x / y + 1));
    }

    /*
     * ===========Modular Operations==================
     */
    static long modInverse(long n, long p) {
        return power(n, p - 2, p);
    }

    static long modAdd(long a, long b) {
        return (a % mod + b % mod) % mod;

    }

    static long modMul(long a, long b) {
        return ((a % mod) * (b % mod)) % mod;
    }

    static long nCrModPFermat(int n, int r) {
        long p = 1000000007;
        if (r == 0)
            return 1;
        long[] fac = new long[n + 1];
        fac[0] = 1;
        for (int i = 1; i <= n; i++)
            fac[i] = fac[i - 1] * i % p;
        return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
    }

    /*
     * ===============================================
     */
    List<Integer> removeDup(ArrayList<Integer> list) {
        List<Integer> newList = list.stream().distinct().collect(Collectors.toList());
        return newList;
    }

    static void ruffleSort(long[] a) {
        int n = a.length;
        Random r = new Random();
        for (int i = 0; i < a.length; i++) {
            int oi = r.nextInt(n);
            long temp = a[i];
            a[i] = a[oi];
            a[oi] = temp;
        }
        Arrays.sort(a);
    }

    static void ruffleSort(int[] a) {
        int n = a.length;
        Random r = new Random();
        for (int i = 0; i < a.length; i++) {
            int oi = r.nextInt(n);
            int temp = a[i];
            a[i] = a[oi];
            a[oi] = temp;
        }
        Arrays.sort(a);
    }

    /*
     * ===========Dynamic prog Recur Section===========
     */

    static int DP[][];
    static int c=0;
    static void dfs(int v,ArrayList<ArrayList<Integer>> g,boolean vis[],int matG[][]) {
        vis[v]=true;
        for(int i:g.get(v)){
            if(!vis[i]){
                dfs(i,g,vis,matG);
                matG[i][v]=c;
                matG[v][i]=c;
                // System.out.println(i+" "+v);
                c++;
            }
        }
    }

    /*
     * ====================================Main=================================
     */
    public static void main(String args[]) throws Exception {
        BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));
        Random rand = new Random();
        int t = 1;
        // t = f.nextInt();
        while (t-- != 0) {
            int n,x;
            n=f.nextInt();
            ArrayList<ArrayList<Integer>> g=new ArrayList<>();
            ArrayList<Pair> ar=new ArrayList<>();
            for(int i=0;i<=n;i++){
                g.add(new ArrayList<>());
            }
            int matG[][]=new int[n+1][n+1];
            for(int i=0;i<=n;i++){
                Arrays.fill(matG[i], -1);
            }
            for(int i=0;i<n-1;i++){
                int u,v;
                u=f.nextInt();
                v=f.nextInt();
                ar.add(new Pair(u,v));
                g.get(u).add(v);
                g.get(v).add(u);
            }
            boolean vis[]=new boolean[n+1];
            dfs(1,g,vis,matG);
            for(Pair i:ar){
                w.write(matG[(int)i.x][(int)i.y]+"\n");
            }
            
        }
        w.flush();
    }
}