Problem: You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such that the following conditions hold:

  * Every label is an integer between 0 and n-2 inclusive. 
  * All the written labels are distinct. 
  * The largest value among MEX(u,v) over all pairs of nodes (u,v) is as small as possible. 



Here, MEX(u,v) denotes the smallest non-negative integer that isn't written on any edge on the unique simple path from node u to node v.

Input

The first line contains the integer n (2 ≤ n ≤ 10^5) — the number of nodes in the tree.

Each of the next n-1 lines contains two space-separated integers u and v (1 ≤ u,v ≤ n) that mean there's an edge between nodes u and v. It's guaranteed that the given graph is a tree.

Output

Output n-1 integers. The i^{th} of them will be the number written on the i^{th} edge (in the input order).

Examples

Input


3
1 2
1 3


Output


0
1


Input


6
1 2
1 3
2 4
2 5
5 6


Output


0
3
2
4
1

Note

The tree from the second sample:

<image>

Solution (in JAVA):

Solution:
import java.io.*;
import java.nio.CharBuffer;
import java.util.*;

public class P1325C {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        List<List<Integer>> links = new ArrayList<>();
        for (int i = 0; i < n; ++i)
            links.add(new LinkedList<>());
        HashMap<Tuple, Integer> linkMap = new HashMap<>();
        for (int i = 0; i < n - 1; ++i) {
            int u = scanner.nextInt() - 1;
            int v = scanner.nextInt() - 1;
            links.get(u).add(v);
            links.get(v).add(u);
            linkMap.put(new Tuple(u, v), i);
        }
        LinkedList<Integer> x = search(0, links);
        LinkedList<Integer> y = search(x.peekLast(), links);
        ArrayList<Integer> diameter = new ArrayList<>(y);
        int[] ans = new int[n - 1];
        Arrays.fill(ans, -1);
        int l = diameter.size();
        ans[linkMap.get(new Tuple(diameter.get(0), diameter.get(1)))] = 0;
        if (l > 2)
            ans[linkMap.get(new Tuple(diameter.get(l - 2), diameter.get(l - 1)))] = 1;
        for (int i = 1, cur = n - 2; i < l - 2; ++i) {
            int u = diameter.get(i);
            int v = diameter.get(i + 1);
            ans[linkMap.get(new Tuple(u, v))] = cur--;
        }

        for (int i = 0, cur = 2; i < n - 1; ++i) {
            if (ans[i] < 0)
                ans[i] = cur++;
            writer.println(ans[i]);
        }

        writer.close();
    }


    private static class Tuple {
        public final int x;
        public final int y;

        public Tuple(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Tuple tuple = (Tuple) o;
            return (x == tuple.x && y == tuple.y)
                    ||
                    (x == tuple.y && y == tuple.x);
        }

        @Override
        public int hashCode() {
            return x + y;
        }
    }

    private static LinkedList<Integer> search(int x, List<List<Integer>> links) {
        LinkedList<Integer> queue = new LinkedList<>();
        HashMap<Integer, Integer> fatherMap = new HashMap<>();
        queue.add(x);
        fatherMap.put(x, x);
        int u = x;
        while (!queue.isEmpty()) {
            u = queue.poll();
            for (int v : links.get(u)) {
                if (!fatherMap.containsKey(v)) {
                    queue.offer(v);
                    fatherMap.put(v, u);
                }
            }
        }
        LinkedList<Integer> ans = new LinkedList<>();
        int father = fatherMap.get(u);
        while (u != father) {
            ans.offerFirst(u);
            u = father;
            father = fatherMap.get(u);
        }
        ans.offerFirst(u);
        return ans;
    }


    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        private SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}