#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T MIN(const T &a, const T &b) {
  return a < b ? a : b;
}
template <typename T>
inline T MAX(const T &a, const T &b) {
  return a > b ? a : b;
}
template <typename T, typename... Args>
inline T MIN(const T &a, const T &b, Args... args) {
  return MIN(MIN(a, b), args...);
}
template <typename T, typename... Args>
inline T MAX(const T &a, const T &b, Args... args) {
  return MAX(MAX(a, b), args...);
}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int dir[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1};
vector<int> g[100010];
bool vis[100010];
int ans[100010], u[100010], v[100010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> u[i] >> v[i];
    g[u[i]].push_back(v[i]);
    g[v[i]].push_back(u[i]);
  }
  int cnt = 0;
  for (int i = 0; i < n - 1; i++) {
    if (g[u[i]].size() == 1 or g[v[i]].size() == 1) {
      vis[i] = 1;
      ans[i] = cnt++;
    }
  }
  for (int i = 0; i < n - 1; i++)
    if (!vis[i]) ans[i] = cnt++;
  for (int i = 0; i < n - 1; i++) cout << ans[i] << '\n';
  return 0;
}
