#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const int maxn = 200001;
using large = int64_t;
long long gcd(long long int a, long long int b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long x1, y1;
  long long d = gcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}
vector<int> v[maxn];
map<pair<int, int>, int> mp;
int ans[maxn];
int a, b, p = 0;
void dfs(int node, int par) {
  for (int child : v[node]) {
    if (child != par) dfs(child, node);
  }
  if (par != 0) {
    if (v[node].size() > 1 && v[par].size() > 1 &&
        p < (v[node].size() - 2 + v[par].size())) {
      a = node;
      b = par;
      p = v[node].size() - 2 + v[par].size();
    }
  }
}
int main() {
  int t;
  long long i, j, k, l, m, n;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> j >> k;
    v[j].push_back(k);
    v[k].push_back(j);
    a = k;
    b = j;
    mp[{j, k}] = mp[{k, j}] = i;
  }
  memset(ans, -1, sizeof(ans));
  dfs(1, 0);
  j = 0;
  ans[mp[{a, b}]] = j++;
  if (v[a].size() < v[b].size()) swap(a, b);
  for (int child : v[a]) {
    if (child != b) {
      ans[mp[{a, child}]] = j++;
    }
  }
  for (int child : v[b]) {
    if (child != a) {
      ans[mp[{b, child}]] = j++;
    }
  }
  for (i = 1; i < n; i++) {
    if (ans[i] == -1) ans[i] = j++;
  }
  for (i = 1; i < n; i++) {
    cout << ans[i] << "\n";
  }
}
