#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
map<pair<int, int>, int> m;
int ind = 0, arr[100005], bio[100005];
queue<int> q;
void bfs() {
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < v[x].size(); i++) {
      if (bio[v[x][i]]) continue;
      arr[m[make_pair(x, v[x][i])]] = ind;
      ind += 1;
      bio[v[x][i]] = 1;
      q.push(v[x][i]);
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    v[a - 1].push_back(b - 1);
    v[b - 1].push_back(a - 1);
    m[make_pair(a - 1, b - 1)] = i;
    m[make_pair(b - 1, a - 1)] = i;
  }
  bio[0] = 1;
  q.push(0);
  bfs();
  for (int i = 0; i < n - 1; i++) {
    cout << arr[i] << "\n";
  }
  return 0;
}
