#include <bits/stdc++.h>
using namespace ::std;
vector<pair<int, int>> ans, tmp;
vector<int> v[100005];
int sz[100005], cnt[100005], par[100005];
int DFS(int i, int p = 0) {
  sz[i] = 1;
  par[i] = p;
  for (auto a : v[i])
    if (a != p) sz[i] += DFS(a, i);
  return sz[i];
}
int main() {
  int n;
  cin >> n;
  for (int i = 1, l, r; i < n; i++)
    cin >> l >> r, v[l].push_back(r), v[r].push_back(l), ans.push_back({l, r});
  DFS(1);
  for (int i = 0; i < n - 1; i++) {
    int t1 = sz[ans[i].first], t2 = sz[ans[i].second];
    if (par[ans[i].first] == ans[i].second) t2 = sz[1] - sz[ans[i].first];
    if (par[ans[i].second] == ans[i].first) t1 = sz[1] - sz[ans[i].second];
    tmp.push_back({t1 * t2, i});
  }
  sort(tmp.begin(), tmp.end(), greater<pair<int, int>>());
  for (int i = 0; i < n - 1; i++) cnt[tmp[i].second] = n - 2 - i;
  for (int i = 0; i < n - 1; i++) cout << cnt[i] << '\n';
}
