#include <bits/stdc++.h>
using namespace std;
void fileio() {}
vector<long long int>* adj;
vector<long long int> leaf;
void dfs(long long int a, long long int p) {
  long long int flag = 0;
  for (auto to : adj[a]) {
    if (to != p) {
      dfs(to, a);
      flag = 1;
    }
  }
  if (flag == 0) leaf[a] = 1;
}
void solve() {
  long long int n;
  cin >> n;
  adj = new vector<long long int>[n];
  vector<pair<long long int, long long int> > edges;
  leaf.assign(n, 0);
  for (long long int i = 0; i <= n - 2; i++) {
    long long int a, b;
    cin >> a >> b;
    adj[a - 1].push_back(b - 1);
    adj[b - 1].push_back(a - 1);
    edges.push_back(make_pair(a - 1, b - 1));
  }
  long long int vtx = -1;
  for (long long int i = 0; i <= n - 1; i++) {
    if (adj[i].size() > 1) {
      vtx = i;
      break;
    }
  }
  if (n <= 3) {
    for (long long int i = 0; i <= n - 2; i++) {
      cout << i << endl;
    }
    return;
  }
  dfs(vtx, -1);
  vector<long long int> ans;
  ans.assign(n - 1, -1);
  long long int flag = 0;
  long long int count = 1;
  for (long long int i = 0; i <= n - 2; i++) {
    if (edges[i].first == vtx || edges[i].second == vtx) {
      if (leaf[edges[i].first] == 0 && leaf[edges[i].second] == 0 &&
          flag == 0) {
        ans[i] = 0;
        flag = 1;
      }
    } else {
      if (leaf[edges[i].first] == 1 || leaf[edges[i].second] == 1)
        ans[i] = count++;
    }
  }
  for (long long int i = 0; i <= n - 1; i++) {
    if (ans[i] == -1) {
      if (flag == 0) {
        ans[i] = 0;
        flag = 1;
        continue;
      }
      ans[i] = count++;
    }
  }
  for (long long int i = 0; i <= n - 2; i++) {
    cout << ans[i] << endl;
  }
}
int32_t main() {
  fileio();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  { solve(); }
  return 0;
}
