#include <bits/stdc++.h>
using namespace std;
vector<set<pair<int, int>>> v;
vector<int> ind, visit, inv;
queue<int> pq;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, i;
  cin >> n;
  int a[n + 2], b[n + 2];
  v.clear();
  v.resize(n + 5);
  visit.clear();
  visit.resize(n + 5);
  inv.clear();
  inv.resize(n + 5);
  ind.clear();
  ind.resize(n + 5);
  for (i = 1; i <= n; i++) {
    visit[i] = 0;
    inv[i] = 0;
  }
  for (i = 0; i < (n - 1); i++) {
    cin >> a[i] >> b[i];
    v[b[i]].insert(make_pair(a[i], i));
    v[a[i]].insert(make_pair(b[i], i));
  }
  int rt = 1;
  for (i = n; i > 0; i--) {
    if (v[i].size() == 1) {
      pq.push(i);
    }
  }
  int p, k = 0;
  while (!pq.empty()) {
    p = pq.front();
    pq.pop();
    for (auto j : v[p]) {
      ind[j.second] = rt;
      rt++;
      v[j.first].erase(make_pair(p, j.second));
      if (v[j.first].size() == 1) {
        pq.push(j.first);
      }
    }
  }
  for (i = 0; i < (n - 1); i++) {
    if (ind[i] == (n - 1))
      cout << "0\n";
    else
      cout << ind[i] << endl;
  }
  return 0;
}
