#include <bits/stdc++.h>
#define ll long long int
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define all(a) a.begin(),a.end()
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define vp vector<pair<ll,ll>>
#define mp make_pair
#define take(v,n)  rep(i,n){ll num; cin>>num; v.pb(num); }
// ll lcm(ll a, ll b){return a*b/__gcd(a, b);}
// ll power(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a; b/=2;a=a*a;}return ans;}
//ll inverse(ll a, ll m){ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0;while (a > 1)
//{  ll q = a / m; ll t = m;  m = a % m, a = t;  t = y;   y = x - q * y;   x = t;}if (x < 0) x += m0; return x;}
//ll nCr(ll n, ll r){if(r > n) return 0; else return ((fact[n]%mod*inverse(fact[r], mod)%mod)%mod*inverse(fact[n-r], mod)%mod)%mod;}
using namespace std;
bool f(ll x,ll y){
    return x>y;
}//for reverse sorting
const int N=200023;
vl g[N],levl[N];
bool vis[N]={0};

void solve(){
    ll u,v,n,tri=0,flag=0,k=3;
    cin>>n;
    ll node[n+1]={0};
    // cout<<node[n];
    vp v1;
    rep(i,n-1){
        cin>>u>>v;
        v1.pb(mp(u,v));
        node[u]++; node[v]++;
        if(flag==0&&node[u]>2){
           tri=u; flag=1;
        }
        else if(flag==0&&node[v]>2){
           tri=v;  flag=1;
        }
    }
    // cout<<tri<<endl;
    ll sp=0;
    if(flag==0) k=0;
    rep(i,n-1){
        if(v1[i].first==tri||v1[i].second==tri)
        cout<<sp++<<endl;
        else
        cout<<k++<<endl;
    }
    
}
int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    // cin>>t;
    rep(i,t){
        solve();
    }
	return 0;
}