#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 int long long
#define ll long long
#define ld long double
#define mset(a, v) memset(a, v, sizeof(a))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define mod 1000000007
#define pi acos(-1)
#define inf LONG_LONG_MAX
#define pb push_back
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define IO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define N 100005

vector<int> a[N];
vector<bool> v(N,0);
map<pair<int,int>,int> mp;

void dfs(int x,int &d)
{
    v[x]=1;
    for(auto &e:a[x])
    {
        if(!v[e])
        {
            mp[{x,e}]=d;
            mp[{e,x}]=d;
            d++;
            dfs(e,d);
        }
    }
}

void solve()
{
    int n;
    cin>>n;
    vector<pair<int,int>> w;
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin>>x>>y;
        w.pb({x,y});
        a[x].pb(y);
        a[y].pb(x);
    }
    int d=0;
    dfs(1,d);
    for(auto &e:w)
    {
        cout<<mp[{e.ff,e.ss}]<<"\n";
    }
}

signed main()
{
    FIO;
    //IO;
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}