#include <bits/stdc++.h>
using namespace std;
int const maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x) { return x << 1; }
inline int rc(int x) { return x << 1 | 1; }
vector<int> e[maxn];
int inedage[maxn], vis[maxn];
int n;
vector<pair<int, int>> g;
map<pair<int, int>, int> mp;
int cnt = 0;
void dfs(int fa, int u) {
  if (vis[u]) return;
  vis[u] = 1;
  if (inedage[u] == 1) {
    mp[{max(u, fa), min(fa, u)}] = cnt++;
  }
  for (auto &v : e[u]) {
    dfs(u, v);
  }
}
int main(void) {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    inedage[u]++;
    inedage[v]++;
    e[u].push_back(v);
    e[v].push_back(u);
    auto p = make_pair(max(u, v), min(u, v));
    mp[p] = -1;
    g.push_back(p);
  }
  int fa = *max_element(inedage + 1, inedage + 1 + n,
                        [](int x, int y) { return x > 1 && y > 1; });
  dfs(-1, fa);
  for (auto &x : g) {
    if (mp[x] == -1) mp[x] = cnt++;
    cout << mp[x] << endl;
  }
  return 0;
}
