  #include <bits/stdc++.h>
  using namespace std;

  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp> 
  using namespace __gnu_pbds;
  #define pll pair<int,string>
  #define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update> 


  #define int long long int 
  #define vi vector<int>
  #define pii pair<long long ,long long>
  
  #define mod 1000000007
  #define hell 998244353
  #define all(x) x.begin(),x.end()
  //#define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define eb push_back
  #define ff first
  #define ss second
  #define rep(n) for(int i=0;i<n;i++)
  #define lb lower_bound
  #define up upper_bound
  
  vi adj[200005];
  void solve()
  { 
        
      int n;
      cin>>n;
      vector<pair<int,int> > v;
      rep(n-1)
      {
         int x,y;
         cin>>x>>y;
         adj[x].push_back(y);
         adj[y].push_back(x);
         if(x>y)
          swap(x,y);
        v.push_back({x,y});
      }
      map<pair<int,int>,int> mp;
      int cnt=1;
      for(int i=1;i<=n;i++)
      {
         if((int)adj[i].size()>=3)
         {
            
            for(int j:adj[i])
            {
                 int a=i;
                 int b=j;
                 if(a>b)
                  swap(a,b);
                mp[{a,b}]=cnt;
                cnt++;
                if(cnt==4)
                  break;
            }
         }
      }
      for(int i=1;i<=n;i++)
      {
          for(int j:adj[i])
          {
             int a=i;
             int b=j;
             if(a>b)
              swap(a,b);
            if(mp[{a,b}]==0)
            {
               mp[{a,b}]=cnt;
               cnt++;
            }
          }
      }
      for(pair<int,int> p:v)
        cout<<mp[p]-1<<"\n";



  }
      
        
    
  
 signed main()
  {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
     
    
    int T;
    T=1;
    
    while(T--)
    {
      solve();
    }
    return 0;
  }  