#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_setPair; 		
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_multiset;
 
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

#define int ll 
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define pb push_back

template<typename T> void max_self(T &a, T b) { a = max(a,b); return;}
template<typename T> void min_self(T &a, T b) { a = min(a,b); return;}
 
const int nax = 1e5 + 5;
const int mod = 1e9 + 7;
const int linf = 1e18 + 1e9 + 5;

int modExpo(int a,int b,int c){
	int answer = 1;
	while(b){
		if(b & 1) answer = ((answer % c) * (a % c)) % c;
		a = ((a % c) * (a % c)) % c;
		b /= 2; 
	}
	return answer;
}

signed main(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int t = 1;
	//cin >> t;
	while(t--){				
		int n;
		cin >> n;
		
		vector<pair<int,int> > adj[nax];
		vector<int> degree(nax,0);
		for(int i = 0; i < n - 1; ++i){
			int u,v;
			cin >> u >> v;
			adj[u].push_back({v,i});
			adj[v].push_back({u,i});
			++degree[u];
			++degree[v];
		}
		
		priority_queue<pair<int,int> > q;
		for(int i = 1; i <= n; ++i) q.push({degree[i],i});
		
		map<int,priority_queue<pair<int,int> > > m;
		for(int i = 1; i <= n; ++i){
			for(auto u : adj[i]){
				m[i].push({degree[u.first],u.second});
			}
		}
		
		vector<int> ans(n - 1,-1);
		int value = n - 2;
		while(!q.empty()){
			pair<int,int> temp = q.top();
			q.pop();
			
			pair<int,int> res = m[temp.second].top();
			m[temp.second].pop();
			
			if(ans[res.second] == -1){
				ans[res.second] = value;
				--value;
			}
			
			temp.first -= 1;
			if(temp.first  > 0) q.push(temp);
		}
		
		for(int i = 0; i < n - 1; ++i) cout << ans[i] << "\n";	
	}
	
	return 0;
}
