#include<bits/stdc++.h> 
using namespace std; 
int main() 
{int n; 
    cin >> n; 
    int b[n-1][2],d[n+1]={0};   int c[n]; 
    for(int i=0;i<n;++i) 
    c[i]=-1;
    int count=0;
    for(int i=0;i<n-1;++i) 
     {cin >>b[i][0]>>b[i][1]; 
         d[b[i][0]]++; 
         d[b[i][1]]++;
     } 
     for(int i=0;i<n+1;++i) 
     if(d[i]==1) 
     count++;   
    /* for(int i=0;i<n+1;++i) 
     cout<<d[i]<<" "; 
     cout<<"\n";*/
     if(count<=2) 
     {for(int i=0;i<n-1;++i) 
     cout<<i<<"\n"; 
         
     } 
     else 
     {int counter=0;
         int e[3] ; 
         for(int i=0;i<n+1;++i) 
         {if(d[i]==1) 
             {e[counter]=i; 
                 counter++;
             } 
             if(counter==3) 
             break;
         } 
         counter=0; 
        // cout<<e[0]<<" "<<e[1]<<" "<<e[2]<<"\n";
         for(int i=0;i<n-1;++i)  
     {if(b[i][0]==e[counter]||b[i][1]==e[counter]) 
         {//cout<<b[i][0]<<" "<<b[i][1]<<" "<<e[counter]<<"\n";
             c[i]=counter;
             counter++; 
             
         } 
         if(counter==3) 
         break;
     } 
    /* for(int i=0;i<n;++i) 
     cout<<c[i]<<" "; 
     cout<<"\n";*/
     for(int i=0;i<n-1;++i) 
     {if(c[i]==-1) 
         { 
             c[i]=counter; counter++;}
         
     } 
     for(int i=0;i<n-1;++i) 
     cout<<c[i]<<"\n";
     }
}