#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
vector<vector<pair<int, int>>> aj(N);
vector<int> ans(N, -1);
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    aj[u].emplace_back(i, v);
    aj[v].emplace_back(i, u);
  }
  for (int v = 1; v <= n; ++v) {
    if (aj[v].size() > 2) {
      int k = 0;
      for (auto p : aj[v]) {
        ans[p.first] = k++;
      }
      for (int i = 0; i < n - 1; ++i) {
        if (ans[i] != -1) {
          cout << ans[i] << endl;
        } else {
          cout << k++ << endl;
        }
      }
      return 0;
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    cout << i << endl;
  }
  return 0;
}
