#include <bits/stdc++.h>
using namespace std;
vector<int> g[100043];
int dp[100043];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  for (int i = 0; i < 100043; i++) dp[i] = -1;
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int x;
    cin >> x;
    int y;
    cin >> y;
    x--;
    y--;
    g[x].push_back(i);
    g[y].push_back(i);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (g[i].size() > 2) {
      dp[g[i][0]] = 0;
      dp[g[i][1]] = 1;
      dp[g[i][2]] = 2;
      ans = 3;
      break;
    }
  }
  for (int i = 1; i < n; i++) {
    if (dp[i] == -1) {
      dp[i] = ans;
      ans++;
    }
  }
  for (int i = 0; i < n - 1; i++) cout << dp[i] << endl;
  return 0;
}
