#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<int> E[N];
int dp[N];
map<pair<int, int>, int> h;
vector<pair<int, int> > d;
int ans[N], p[N];
int cnt = 0;
void dfs(int node, int pred) {
  int ans = 0;
  p[node] = pred;
  for (auto it : E[node]) {
    if (it != pred) {
      dfs(it, node);
      ans += dp[it];
    }
  }
  dp[node] = ans + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    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;
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    d.push_back({dp[i], i});
  }
  sort(d.begin(), d.end());
  for (int i = 0; i < d.size() - 1; i++) {
    ans[h[make_pair(d[i].second, p[d[i].second])]] = cnt;
    cnt++;
  }
  for (int i = 1; i <= n - 1; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
