#include <bits/stdc++.h>
using namespace std;
long long solve() {
  long long n;
  cin >> n;
  long long x, y;
  vector<long long int> adj[n + 1];
  map<pair<long long, long long>, long long> m;
  vector<pair<long long int, long long int> > v;
  for (long long int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    v.push_back({x, y});
  }
  queue<long long> q;
  q.push(1);
  long long curr = 1;
  vector<long long int> vis(n + 1, 0);
  vis[curr] = 1;
  long long ans = 0;
  while (!q.empty()) {
    curr = q.front();
    q.pop();
    for (long long int i = 0; i < (long long int)adj[curr].size(); i++) {
      if (vis[adj[curr][i]] == 0) {
        q.push(adj[curr][i]);
        vis[adj[curr][i]] = 1;
        m[{curr, adj[curr][i]}] = ans++;
      }
    }
  }
  for (long long int i = 0; i < n - 1; i++) {
    cout << m[{v[i].first, v[i].second}] << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  for (long long int l = 0; l < t; l++) {
    solve();
  }
}
