#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define NI_DEGI ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define ll long long
#define pb push_back
#define pll pair<ll,ll>
#define ppl pair<pll,ll>
#define plp pair<ll,pll>
#define MAXN 130
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define inf INT_MAX
long long mod = 1e9+7;
int dx[] = {1,1,0,-1,-1,-1, 0, 1};
int dy[] = {0,1,1, 1, 0,-1,-1,-1};
int bit(int x,int i){
  return ((x>>(i-1))&1);
}
ll power(ll a,ll n){
  ll ans=1;
  while(n>0){
    if(n%2)ans=(ans*a)%mod;
    n=n>>1;
    a=(a*a)%mod;
  }
  return ans;
}

int root(int par[],int i){
    if(par[i]!=i)par[i]=root(par,par[i]);
    return par[i];
}
void make_union(int par[],int size[],int a,int b){
    int ra=root(par,a);
    int rb=root(par,b);
    if(ra==rb)return;
    /*if(ra>rb){
      par[rb]=ra;
    }
    else par[ra]=rb;
    return;*/
    
    if(size[ra]<size[rb]){
        par[ra]=par[rb];
        //size[rb]+=size[ra];
    }
    else{
        par[rb]=par[ra];
        //size[ra]+=size[rb];
    }
    if(size[ra]==size[rb])
    size[ra]=size[rb]+1;
}
ll inv(ll n){
  return power(n,mod-2);
}
ll fact[200005];
ll ncr(ll n, ll r){
  if(n<0)return 1;
  if(n<r)return 0;
  ll nn=fact[n]%mod;
  ll rr=fact[r]%mod;
  ll nr=fact[n-r]%mod;
  ll x=(rr*nr)%mod;
  ll ans=nn*inv(x);
  return ans%mod;
}
inline ll digit(ll x){
  ll a=0;
  while(x){
    a++;x/=10;
  }
  return a;
}
ll chk(ll mid,int tag){
  ll ans=0;
  for(int i=1;i<=mid;i*=10){
    if(tag)ans+=(mid-i+1)*(mid-i+2)/2;
    else ans+=(mid-i+1);
  }
  return ans;
}
ll search(ll l, ll r,int tag,ll k){
  while(l<r){
    ll mid=(l+r+1)/2;
    if(chk(mid,tag)<k)l=mid;
    else r=mid-1;
  }
  return l;
}
int main()
 {
   NI_DEGI
   ll n;cin>>n;
   vector<ll>G[n+1];
   map<pair<ll,ll>,ll>M;
   for(int i=0;i<n-1;i++){
     ll x,y;cin>>x>>y;
     G[x].pb(y);
     G[y].pb(x);
     if(x>y)swap(x,y);
     M[{x,y}]=i;
   }
   vector<ll>ans(n,-1);
   ll x=0;
   for(int i=0;i<n;i++){
     if(G[i].size()>=3){
       for(auto j:G[i]){
         int u=i,v=j;
         if(u>v)swap(u,v);
         ans[M[{u,v}]]=x++;
       }
     }
   }
   for(int i=0;i<n-1;i++){
     if(ans[i]==-1){
       cout<<x++<<"\n";
     }
     else cout<<ans[i]<<"\n";
   }
  return 0;
  }