#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define m_p make_pair
#define pb push_back 
#define ppb pop_back
#define f first
#define s second
#define pii pair<int,int>
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define double long double
const double pi=3.14159265358979;
const int mod=1e9+7;
//freopen("b_small.in","r", stdin);
int takemod(int a,int mod){return ((a%mod)+mod)%mod;}
int power(int  b, int  p){if(p==0)return 1;else if(p%2==0){int q=power(b,p/2);return ((q)*(q));}else return ((b)*(power(b,p-1)));}
int powerm(int  b, int  p){if(p==0)return 1;else if(p%2==0){int q=powerm(b,p/2);return ((q%mod)*(q%mod))%mod;}else return ((b%mod)*(powerm(b,p-1)%mod))%mod;}
bool isprime( int  n){if(n==1)return false;if(n==2 or n==3)return true; int  lim=sqrt(n); int  i=2;while(i<=lim){if(n%i==0)return false; i++;}return true;}
vector< int > factors( int  n){vector< int > a;a.pb(1);int  lim=sqrt(n),i=2;while(i<=lim){if(n%i==0){a.pb(i);if(i!=n/i)a.pb(n/i);}i++;}if(n!=1)a.pb(n);sort(a.begin(),a.end());a.pb(n);return a;}
vector<pii> pf_with_count(int  b){ pii p;vector<pii>pf;int  count=0;while(b%2==0){b/=2;count++;}if(count>0){p.f=2;p.s=count;pf.pb(p);}int i=3;while(i<=sqrt(b)){count=0;while(b%i==0){b/=i;count++;}if(count>0){p.f=i;p.s=count;pf.pb(p);}i+=2;}if(b>2) {p.f=b;p.s=1;pf.pb(p);} sort(pf.begin(),pf.end());return pf;}
int  bs_t_i(string s){int  l=strtoull(s.c_str(),NULL,2);return l;}
string  i_to_bs(int  n){string s = bitset< 30 >( n ).to_string();return s;}
int lcm(int a,int b){return (a*b)/__gcd(a,b);}
  // ofstream outfile;
  // outfile.open("phele2.in"); 
  // outfile << 2*n << endl;
int inf=1e18;
int arr[100002];
int vis[100002];
map<pii,int> mp;
vector<int> v[100000+1];
int ind=0;
void dfs(int i)
{
  vis[i]=1;
  int j=0;
  while(j<v[i].size())
  {
    if(!vis[v[i][j]])
    {
      mp[make_pair(min(i,v[i][j]),max(i,v[i][j]))]=arr[ind];
      ind++;
      dfs(v[i][j]);
    }
    j++;
  }
}
void solve()
{   
  int n;
  cin>>n;
  
  int i=0;
  
  vector<pii> ans;
  while(i<n-1)
  {
    int a,b;
    cin>>a>>b;
    v[a].pb(b);
    v[b].pb(a);
    ans.pb({min(a,b),max(a,b)});
    i++;
  }

  i=0;
  int j=n-2;
  int count=0;
  while(i<=j)
  {
    arr[i]=count;
    count++;
    if(j>i)arr[j]=count;
    count++;
    i++;
    j--;
  }
  swap(arr[0],arr[(n-1)/2]);
  
  fill(vis,vis+n+1,0);

  
  dfs(1);
  

  // i=0;
  // while(q.size()>0)
  // {
  //   int v1=q.front();
  //   q.pop();
  //   int j=0;
  //   while(j<v[v1].size())
  //   {
  //     if(!vis[v[v1][j]])
  //     {
  //       vis[v[v1][j]]=1;
  //       q.push(v[v1][j]);
  //       mp[{min(v1,v[v1][j]),max(v1,v[v1][j])}]=arr[i];
  //       i++;
  //     }
  //     j++;
  //   }
  // }


 
 
  i=0;
  while(i<n-1)
  {
    cout<<mp[ans[i]]<<endl;
    i++;
  }


}


signed main()
{
  ios;
  int t=1;
  //cin>>t;
  while(t--)solve();  
}

 

 
 