#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    pair<int,int>p[n-1];
    int v[n]={0};
    for (int i=0;i<n-1;i++)
    {
        cin>>p[i].first>>p[i].second;
        v[p[i].first-1]++;
        v[p[i].second-1]++;
    }
    int z=0,s=n-2;
    for (int i=0;i<n-1;i++)
    {
        if (v[p[i].first-1]>2||v[p[i].second-1]>2)
            cout<<z++<<endl;
        else
            cout<<s--<<endl;
    }
}
