#include <bits/stdc++.h>

using namespace std;
vector<pair<int,int>> vect;
vector<int> ava;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int arr[n+5] ={ 0 };
	for(int i=0;i<n+5;++i)
		arr[i] = 0;
	int a,b;
	bool f = false;
	int v = 0;
	for(int i=0;i<n-1;++i){
	 	cin>>a>>b;
	 	arr[a]++;
	 	arr[b]++;
	 	if(arr[a]>2 && !f){
	 	  f = true;
	 	  v = a;
	 	}
	 	if(arr[b]>2 && !f){
	 	  f = true;
	 	  v = b;
	 	}
	 	vect.push_back({a,b});
	}
	int cnt1 = 0;
	int cnt2 = 3;
	//cout<<f<<endl; 
	if(!f){
	 	for(int i =0;i<vect.size();++i){
	 	 	cout<<i<<endl;
	 	}
	}
	else{
		for(int i=0;i<vect.size();++i){
	 	  if(vect[i].first == v || vect[i].second == v){
	 	   	 cout<<cnt1<<endl;
	 	   	 cnt1++;
	 	  }
	 	  else{
	 	   	cout<<cnt2<<endl;
	 	   	cnt2++;
	 	  }
		}
	}
	return 0;
}