#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<pair<int, int> > E[N];
int ans[N];
int cnt = 0;
void dfs(int node, int pred, int inde) {
  for (int i = 0; i < E[node].size(); i++) {
    if (E[node][i].first != pred) {
      dfs(E[node][i].first, node, i);
    }
  }
  if (pred) {
    ans[E[pred][inde].second] = cnt;
  }
  cnt++;
}
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, i});
    E[second].push_back({first, i});
  }
  dfs(1, 0, 0);
  for (int i = 1; i <= n - 1; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
