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

public class Solution {
  // static int dp[][]=new int[10001][10001];
  static int pos=0;
     static ArrayList<Integer> graph[];
     static int diff[];
     static String ans[];
     static int dp[];
     static ArrayList<Integer> newgraph[];
     static int parent[];
     static boolean vis[];
     static int k;
     static int seive[]=new int[1000001];
     static int dis[]=new int[1000001];
     static int subtree[]=new int[1000001];
     static int N =1000001;
     static HashSet<String> hm=new HashSet<>();
     static HashSet<String> hm1=new HashSet<>();
     static HashMap<Integer, Character> hash=new HashMap<>();
     static Stack<Integer> st=new Stack<>();
     static TreeMap<Integer,ArrayList<String>> tm=new TreeMap<>();
     static int time=0;
     static int components=0;
     public static void main(String[] args) {
       Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
       StringBuilder sb=new StringBuilder();
       HashMap<String,Integer> hm=new HashMap<>();
        int n=sc.nextInt();
        graph=new ArrayList[n];
        for( int i=0;i<n;i++)
        {
          graph[i]=new ArrayList<>();
        }
        ArrayList<String> adj=new ArrayList<>();
        for( int i=0;i<n-1;i++)
        {
          int u=sc.nextInt();
          int v=sc.nextInt();
          u--;
          v--;
          graph[u].add(v);
          graph[v].add(u);
          hm.put(Math.min(u,v)+" "+Math.max(u, v),0);
          adj.add(Math.min(u,v)+" "+Math.max(u, v));
        }
        vis=new boolean[n];
        dp=new int[n];
        ans=new String[n];

        dfs(0,-1);
        for( int i=0;i<n;i++)
        {
          //System.out.println(dp[i]+" "+ans[i]);
          if(ans[i]!=null)
          {
            if(!tm.containsKey(dp[i]))
          tm.put(dp[i],new ArrayList<String>());
          ArrayList<String> p=tm.get(dp[i]);
          p.add(ans[i]);
          tm.put(dp[i],p);
        }
        }
        int mex=n-2;
        for( Map.Entry<Integer, ArrayList<String>> entry: tm.entrySet())
        {
          Integer x=entry.getKey();
          ArrayList<String> value=entry.getValue();
            //System.out.println(x+" "+value);
            for( int j=0;j<value.size();j++)
        {  hm.put(value.get(j),mex);
          mex--;
        }
        }
        for( int i=0;i<n-1;i++)
        {
          sb.append(hm.get(adj.get(i)));
          sb.append("\n");
        }
        System.out.println(sb.toString());
}
public static int dfs( int u, int par)
{
  vis[u]=true;
  for( int i=0;i<graph[u].size();i++)
  {
    int v=graph[u].get(i);
    if(!vis[v])
    {
      int k=dfs(v, u);
      dp[u]=Math.max(k,dp[u]);

    }
  }
  if(par!=-1)
  ans[u]=Math.min(u, par)+" "+Math.max(u,par);
  return dp[u]+1;
}


}

class Pair
{
long x,y;
Pair(long x, long y)
{
this.x=x;
this.y=y;
}
}
class myComparator implements Comparator<Pair>
{
public int compare(Pair a, Pair b)
{
return Long.compare(b.y, a.y);
}
}
