#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
vector<pair<int, int> > edge[maxn];
int ans[maxn];
int vis[maxn];
int p, q;
void dfs(int x) {
  for (auto it : edge[x]) {
    if (!vis[it.first]) {
      if ((int)(edge[it.first]).size() == 1)
        ans[it.second] = p++;
      else {
        ans[it.second] = q--;
      }
      vis[it.first] = 1;
      dfs(it.first);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, u, v;
  cin >> n;
  for (int i = (0); i < (n - 1); ++i) {
    cin >> u >> v;
    edge[u].push_back(make_pair(v, i));
    edge[v].push_back(make_pair(u, i));
  }
  p = 0, q = n - 2;
  vis[1] = 1;
  dfs(1);
  for (int i = (0); i < (n - 1); ++i) cout << ans[i] << '\n';
  return 0;
}
