#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
const int p = 110;
vector<int> a[maxn];
pair<int, int> s[maxn];
int ans[maxn];
int main() {
  int n;
  cin >> n;
  memset(ans, -1, sizeof(ans));
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    a[u].push_back(v);
    a[v].push_back(u);
    s[i] = {u, v};
  }
  int idx = 0;
  for (int i = 0; i < n - 1; i++) {
    int u = s[i].first, v = s[i].second;
    if (a[u].size() == 1 || a[v].size() == 1) {
      ans[i] = idx++;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (ans[i] == -1) ans[i] = idx++;
  }
  for (int i = 0; i < n - 1; i++) printf("%d\n", ans[i]);
}
