#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100001];
vector<pair<int, int> > edgs;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  map<int, bool> mp;
  vector<int> nums(n - 1);
  for (int c1 = 0; c1 < n; c1++) {
    int x, y;
    cin >> x >> y;
    if (c1 < n - 1) nums[c1] = -1;
    adj[x].push_back(y);
    adj[y].push_back(x);
    edgs.push_back({x, y});
    if (adj[x].size() > 1) {
      mp[x] = 0;
    } else {
      mp[x] = 1;
    }
    if (adj[y].size() > 1) {
      mp[y] = 0;
    } else {
      mp[y] = 1;
    }
  }
  int cnt = 0;
  for (int c1 = 0; c1 < n - 1; c1++) {
    if (mp[edgs[c1].first] || mp[edgs[c1].second]) {
      nums[c1] = cnt++;
    }
  }
  for (int c1 = 0; c1 < n - 1; c1++) {
    if (nums[c1] == -1) {
      nums[c1] = cnt++;
    }
  }
  for (int c1 = 0; c1 < n - 1; c1++) {
    cout << nums[c1] << '\n';
  }
  return 0;
}
