#include <bits/stdc++.h>
#define int long long int
#define ff first
#define ss second
#define pb push_back

using namespace std;

const int MAX_N = 1e5 + 7, delta = 10343;
int cnt[MAX_N];
map <pair <int, int>, int > mp;
vector <int> adj[MAX_N];
int32_t main()
{
    int n; cin >> n;

    for(int i = 1; i < n; i++)
    {
        int a, b; cin >> a >> b;
        cnt[a]++, cnt[b]++;
        adj[a].pb(b), adj[b].pb(a);
        mp[{a,b}] = mp[{b, a}] = i;
    }
    int ans[3] = {}, idx= 0;
    for(int i = 1; i <= n; i++)
    {
        if(cnt[i] == 1)
        {
            ans[idx++] = i;
            if(idx > 2)
                break;
        }
    }
    //cout << endl;
  //  cout << ans[0] << " " << ans[1] <<  "  " << ans[2]<< endl;
    int sz = 2;
    int m = 0;
    int j[n] = {};
    j[mp[{ans[0], adj[ans[0]][0]}]] = 1;
    j[mp[{ans[1], adj[ans[1]][0]}]] = 2;
    if(idx >= 3)
        j[mp[{ans[2], adj[ans[2]][0]}]] = 3, sz++;
    for(int i = 1; i < n; i++)
    {
       if(j[i]) cout << j[i] - 1 << endl;
       else cout << sz++ << endl;
    }
    return 0;
}
