

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

public class CFA {
    public static void main(String[] args) throws FileNotFoundException, InterruptedException {
        InputStream stream = System.in;
        Logger logger = new Logger();
        if (args.length>1 && args[0].equals("LOCAL") && args[1].equals("YES")) {
            File inputFile = new File("resources/input.in");
            stream = new DataInputStream(new FileInputStream(inputFile));
            logger.enableLogging(true, "resources/logs.txt");
        }
        InputReader in = new InputReader(stream);
        PrintWriter out = new PrintWriter(System.out);
        Thread th = new Thread(null, () -> new Task1().solve(in, out, logger), "Task1", 1 << 24);
        th.start();
        th.join();
        out.close();
        logger.close();
    }

    static class Edge {
        Integer first, second;
        public Edge(int x, int y) {
            this.first = x;
            this.second = y;
        }

        public int other(int x) {
            if(x==first) {
                return second;
            }
            return first;
        }

        @Override
        public boolean equals(Object anObject) {
            Edge x = (Edge)anObject;
            int f = x.first;
            int s = x.second;
            return (first==f && second==s) || (first==s && second==f);
        }

        @Override
        public int hashCode(){
            return new Integer(31*first+second).hashCode();
        }
    }

    static class Task1 {
        ArrayList<Edge>[] adj;
        void solve(InputReader in, PrintWriter out, Logger logger) {
            int n = in.nextInt();
            adj = new ArrayList[n];
            for (int i=0; i<n; i++) {
                adj[i] = new ArrayList<>();
            }

            ArrayList<Edge> edges = new ArrayList<>();
            for(int i=0; i<n-1; i++) {
                int u = in.nextInt()-1, v = in.nextInt()-1;
                Edge e = new Edge(u, v);
                adj[u].add(e);
                adj[v].add(e);
                edges.add(e);
            }

            HashSet<Edge> leafEdges = new HashSet<>();
            for (int i=0; i<n; i++) {
                if (adj[i].size() == 1) {
                    leafEdges.add(adj[i].get(0));
                }
            }
            logger.log(leafEdges.size());
            int l = 0, nl = leafEdges.size();
            for (int i=0; i<n-1; i++) {
                Edge e = edges.get(i);
                if (leafEdges.contains(e)) {
                    out.println(l++);
                } else {
                    out.println(nl++);
                }
            }
        }
    }

    static class Logger {
        private PrintWriter logger;
        private boolean loggingEnabled;

        void enableLogging(boolean enable, String filename) {
            this.loggingEnabled = enable;
            try {
                if (loggingEnabled) this.logger = new PrintWriter(filename);
            } catch (FileNotFoundException ignored) {
            }
        }

        void log(Object s) {
            if (loggingEnabled) {
                logger.print(s.toString());
            }
        }

        void logln(Object s) {
            if (loggingEnabled) {
                logger.println(s.toString());
            }
        }

        void close() {
            if (loggingEnabled) logger.close();
        }
    }

    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, numChars;
        private SpaceCharFilter filter;

        InputReader(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        interface SpaceCharFilter {
            boolean isSpaceChar(int ch);
        }
    }
}
