#include <bits/stdc++.h>
using namespace std;
void vin(vector<long long int> &v, long long int t) {
  for (long long int i = 0; i < t; i++) cin >> v[i];
}
void vout(vector<long long int> &v, long long int t) {
  for (long long int i = 0; i < t; i++) cout << v[i] << " ";
  cout << endl;
}
void ingraph(vector<vector<long long int>> &graph, long long int m) {
  long long int x, y;
  for (long long int i = 0; i < m; i++) {
    cin >> x >> y;
    x--, y--;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
}
int main() {
  long long int n;
  cin >> n;
  vector<vector<long long int>> gr(n);
  long long int a, b;
  vector<long long int> ans(n - 1, -1);
  for (long long int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    gr[--a].push_back(i);
    gr[--b].push_back(i);
  }
  long long int mx = 0, cur = 0;
  for (long long int i = 0; i < n; i++) {
    if (gr[i].size() > mx) {
      mx = gr[i].size();
      cur = i;
    }
  }
  long long int res = -1;
  for (long long int i = 0; i < gr[cur].size(); i++) ans[gr[cur][i]] = ++res;
  for (long long int i = 0; i < n - 1; i++) {
    if (ans[i] == -1) ans[i] = ++res;
  }
  for (long long int i = 0; i < n - 1; i++) cout << ans[i] << endl;
  return 0;
}
