#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<pair<int, int> > e;
int n, dg[N], ans[N], rn;
vector<pair<int, int> > gr[N];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  rn = n - 2;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    dg[x]++, dg[y]++;
    gr[x].push_back({y, i}), gr[y].push_back({x, i});
    e.push_back({x, y});
  }
  memset(ans, -1, sizeof(ans));
  for (int i = 0; i < e.size(); i++) {
    int x = e[i].first, y = e[i].second;
    if (dg[x] + dg[y] - 2 < n - 2 || i == (int)e.size() - 1) {
      for (auto p : gr[x]) {
        if (p.first != y)
          ans[p.second] = rn--;
        else
          ans[p.second] = 0;
      }
      for (auto p : gr[y]) {
        if (p.first != x)
          ans[p.second] = rn--;
        else
          ans[p.second] = 0;
      }
      break;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (ans[i] == -1)
      cout << rn << "\n", rn--;
    else
      cout << ans[i] << "\n";
  }
  return 0;
}
