import javafx.util.Pair;

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

public class CF1325C {

    public static void main(String ...args) {
        Reader in = new Reader();
        Writer out = new Writer();
        int n = in.nextInt();
        ArrayList<Pair<Integer, Integer>> edges = new ArrayList<>();
        int[] degree = new int[n+1];
        for(int i = 1;i<n;i++) {
            int u = in.nextInt();
            int v = in.nextInt();
            edges.add(new Pair<>(u,v));
            degree[u]++;
            degree[v]++;
        }

        int small = 0;
        int large = n-2;
        int[] ans = new int[n-1];

        for(int i = 0;i<n-1;i++) {
            Pair<Integer, Integer> edge = edges.get(i);
            if (degree[edge.getKey()] == 1 || degree[edge.getValue()] == 1) {
                ans[i] = small++;
            } else {
                ans[i] = large--;
            }
        }

        for(int i: ans) {
            out.println(i);
        }
        out.flush();
    }

}


class Reader {
    private StringTokenizer a;
    private BufferedReader b;
    Reader () {
        a = null;
        try {
            b = new BufferedReader (new InputStreamReader (System.in)); // for file IO, replace this with new FileReader ("in.txt")
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public String next () {
        while(a == null || !a.hasMoreTokens()) {
            try {
                a = new StringTokenizer (b.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return a.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(this.next());
    }
    public long nextLong () {
        return Long.parseLong(this.next());
    }
    public double nextDouble () {
        return Double.parseDouble(this.next());
    }
    public String nextLine() {
        try {
            return b.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}
class Writer {
    private PrintWriter a;
    private StringBuffer b;
    Writer () {
        try {
            a = new PrintWriter (System.out); // for file IO, replace this with new FileWriter ("out.txt")
        } catch (Exception e) {
            e.printStackTrace();
        }
        b = new StringBuffer ("");
    }
    public void print (Object s) {
        b.append(s);
    }
    public void println(Object s) {
        b.append(s).append('\n');
    }
    public void flush () {
        a.print(b);
        a.flush();
        a.close();
    }
}
