#include <bits/stdc++.h>
using namespace std;
long long int n, a, b, w, iceri, wm, tur;
long long int vis[100005];
map<pair<long long int, long long int>, long long int> mp;
vector<long long int> v[100005];
queue<long long int> s;
pair<long long int, long long int> tut[100005];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (long long int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    v[b].push_back(a);
    v[a].push_back(b);
    tut[i] = {a, b};
  }
  s.push(1);
  wm = n - 2;
  while (!s.empty()) {
    iceri = s.front();
    s.pop();
    vis[iceri] = 1;
    for (long long int i = 0; i < v[iceri].size(); i++) {
      if (vis[v[iceri][i]] == 0) {
        s.push(v[iceri][i]);
        if (tur % 2 == 0) {
          mp[{iceri, v[iceri][i]}] = w;
          mp[{v[iceri][i], iceri}] = w;
          tur++;
          w++;
        } else {
          mp[{iceri, v[iceri][i]}] = wm;
          mp[{v[iceri][i], iceri}] = wm;
          tur++;
          wm--;
        }
      }
    }
  }
  for (long long int i = 0; i < n - 1; i++) {
    cout << mp[tut[i]] << endl;
  }
}
