#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
 
#define int long long int
#define pb push_back
#define mp make_pair
#define loop(i,x,n) for(int i=x;i<=n;i++)
#define rloop(i,x,n) for(int i=x;i>=n;i--)
#define ff first
#define ss second
#define N4RUTO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,  
tree_order_statistics_node_update>
ordered_set;

bool comp(vector<int> a, vector<int> b){
    return a.size()<b.size();
}
int32_t main(){
    N4RUTO;
    int t;
    t=1;
    // cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<vector<int>> a(n);
        loop(i,0,n-2){
            int x,y;
            cin>>x>>y;
            a[i].push_back(x);
            a[i].push_back(y);
        }
        vector<vector<int>> adj(n+1);
        loop(i,0,n) adj[i].push_back(i);
        loop(i,0,n-2){
            adj[a[i][0]].push_back(a[i][1]);
            adj[a[i][1]].push_back(a[i][0]);
        }
        // cout<<"\n";
        // loop(i,1,n){
        //     loop(j,0,adj[i].size()-1) cout<<adj[i][j]<<" ";
        //     cout<<"\n";
        // }
        sort(adj.begin(),adj.end(),comp);
        // cout<<"\n";
        // loop(i,1,n){
        //     loop(j,0,adj[i].size()-1) cout<<adj[i][j]<<" ";
        //     cout<<"\n";
        // }
        // cout<<"\n";
        map<pair<int,int>,int> ans;

        int k = 0;
        loop(i,1,n){
            if(adj[i].size()>2) break;
            pair<int,int> p;
            p.first = min(adj[i][0],adj[i][1]);
            p.second = max(adj[i][0],adj[i][1]);
            ans[p] = i-1;
            k = i-1;
        }
        k++;
        // for(auto it:ans){
        //     cout<<it.first.first<<" "<<it.first.second<<" "<<it.second<<"\n";
        // }
        // cout<<"\n";
        loop(i,0,n-2){
            pair<int,int> p;
            p.first = min(a[i][0],a[i][1]);
            p.second = max(a[i][0],a[i][1]);
            if(ans.find(p)!=ans.end()) 
                cout<<ans[p]<<"\n";
            else cout<<k++<<"\n";
        }
    }
    return 0;
}