#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9, MOD = 1e9 + 7;
int n, ans[N];
vector<pair<int, int>> G[N];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    G[--u].push_back({--v, i});
    G[v].push_back({u, i});
  }
  int id = 0;
  memset(ans, -1, n * sizeof ans[0]);
  for (int i = 0; i < n; ++i) {
    if (G[i].size() == 1 && ans[G[i][0].second] == -1)
      ans[G[i][0].second] = id++;
  }
  for (int i = 0; i < n - 1; ++i) {
    if (ans[i] == -1) ans[i] = id++;
    printf("%d\n", ans[i]);
  }
  return 0;
}
