#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int Inf = 1e9 + 7;
const long long INF = 1e18 + 7;
int res[N];
vector<int> g[N];
map<pair<int, int>, int> q;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    res[i] = Inf;
    g[x].push_back(y);
    g[y].push_back(x);
    q[{x, y}] = i;
  }
  int id = 0, sz = 0;
  for (int i = 0; i < n; ++i) {
    if (sz < g[i].size()) {
      sz = g[i].size();
      id = i;
    }
  }
  int ed = 0;
  for (int x : g[id]) {
    int ind = q[{id, x}];
    res[ind] = ed++;
  }
  for (int i = 0; i < n - 1; ++i) {
    if (res[i] == Inf) {
      res[i] = ed++;
    }
    cout << res[i] << '\n';
  }
}
