#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;
void dfs(int node, int pred) {
  p[node] = pred;
  dp[node] = dp[pred] + 1;
  for (auto it : E[node]) {
    if (it != pred) {
      dfs(it, node);
    }
  }
}
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;
  }
  dp[0] = 1;
  dfs(1, 0);
  int l, r;
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    if (dp[i] > mx) {
      mx = dp[i];
      l = i;
    }
  }
  dfs(l, 0);
  mx = 0;
  for (int i = 1; i <= n; i++) {
    if (dp[i] > mx) {
      mx = dp[i];
      r = i;
    }
  }
  cnt = n - 2;
  while (p[l] != 0) {
    ans[h[make_pair(l, p[l])]] = cnt;
    cnt--;
    l = p[l];
  }
  while (p[r] != 0) {
    ans[h[make_pair(r, p[r])]] = cnt;
    cnt--;
    r = p[r];
  }
  for (int i = 1; i <= n - 2; i++) {
    if (ans[i] == -1) {
      ans[i] = cnt;
      cnt--;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
