#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const long long LINF = 1000000000000000000;
const long long MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int>> G(n);
  vector<int> ans(n, -1);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    G[u].push_back(i);
    G[v].push_back(i);
  }
  int cur = 0;
  for (int v = 0; v < n; v++) {
    if ((int)G[v].size() < 3) continue;
    for (auto e : G[v])
      if (ans[e] == -1) ans[e] = cur++;
  }
  for (int e = 0; e < n; e++)
    if (ans[e] == -1) ans[e] = cur++;
  for (int i = 0; i < n - 1; i++) cout << ans[i] << endl;
}
