import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            int E[][] = new int[N - 1][2];
            for (int i = 0; i < N - 1; i++)
            {
                E[i][0] = in.nextInt();
                E[i][1] = in.nextInt();
            }

            Set<Integer> hasParent = new HashSet<>();
            for (int i = 0; i < N - 1; i++)
            {
                hasParent.add(E[i][1]);
            }
            int nChildren[] = new int[N + 1];
            for (int i = 0; i < N - 1; i++)
            {
                nChildren[E[i][0]]++;
            }

            int nFound = -1;
            int max = 0;

            Iterator<Integer> iterator = hasParent.iterator();

            while (iterator.hasNext())
            {
                int n = iterator.next();
                if (hasParent.contains(n) && nChildren[n - 1] > 0)
                {
                    if (max < nChildren[n - 1])
                    {
                        max = nChildren[n - 1];
                        nFound = n;
                    }
                }
            }

            if (nFound == -1)
            {
                printSpecial(out, N);
                return;
            }

            int answer[] = new int[N - 1];
            int k = 1;
            int j = 3;
            boolean hasPlaced0 = false;
            for (int i = 0; i < N - 1; i++)
            {
                if (E[i][1] == nFound && !hasPlaced0)
                {
                    answer[i] = 0;
                    hasPlaced0 = true;
                } else if (E[i][0] == nFound)
                {
                    answer[i] = k;
                    k++;
                } else
                {
                    answer[i] = j;
                    j++;
                }
            }

            for (int i = 0; i < N - 1; i++)
            {
                out.println(answer[i]);
            }
        }

        private void printSpecial(PrintWriter out, int N)
        {
            for (int i = 0; i < N - 1; i++)
            {
                out.println(i);
            }
        }

    }
}

