#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<int> E[N];
map<pair<int, int>, int> h;
int dp[N];
int ans[N], p[N];
int cnt = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    ans[i] = -1;
    int first, second;
    cin >> first >> second;
    E[first].push_back(second);
    E[second].push_back(first);
    h[make_pair(first, second)] = h[make_pair(second, first)] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (E[i].size() == 1) {
      if (h.find(make_pair(i, E[i][0])) != h.end()) {
        ans[h[make_pair(i, E[i][0])]] = cnt;
        cnt++;
        h.erase(make_pair(i, E[i][0]));
        h.erase(make_pair(E[i][0], i));
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (ans[i] == -1) {
      ans[i] = cnt;
      cnt++;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
