#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define mem(a,v) memset(a,v,sizeof(a))
using namespace std;
// *************************PERSONAL USE*************************************************

// vector<vector<int> > vec(20005 , vector<int> (20005, 0));  5 digit
// vector<int>vec(400000000, 0); 9 digit
// vector<pair<int, int>>vec// vec.push_back({x, y}); // vec[i].second, vec[i].first
// vs.resize(unique(vs.begin(), vs.end()) - vs.begin()); just unique value after sort
// const int N=1e6; 7 digit
// int mod[N+2] ---- all values set to zero automatically(n must be constant)
// int upper1 = upper_bound(mxList, mxList+n, value) - mxList; //over or equal cnt
// int upper1 = lower_bound(mxList, mxList+n, value) - mxList; //cnt just over not equal
// ll p=upper_bound(x[c].begin(),x[c].end(),v)-x[c].begin(); two dimensional vector
// #define mem(a, v) memset(a, v, sizeof(a))
// iota(arr,arr+n,value) arr- 5 6 7 8, if value=5
/*
int modInverse(int a, int m)
{
    int m0 = m;
    int y = 0, x = 1;
    if (m == 1)return 0;
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)x += m0;
    return x;
}*/

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);

    int n,a,b;cin>>n;
    vector<int>res;
    int frst[n+2]={0};
    int l=0,r=n-2;
    for(int i=0; i<n-1; i++){
            cin>>a>>b;
            if(frst[a]==0){
                    res.push_back(r);
                    r--;
            }
            else{
                    res.push_back(l);
                    l++;
            }
            frst[a]=1;

    }
    for(auto x:res){
            cout<<x<<endl;
    }
    return 0;
}

