#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int N = 1e5 + 5;
const int lgN = 1e6 + 5;
const int te = 3e8 + 1;
const signed long long MOD = 998244353;
const long double pi = 3.141592653589793238462643383;
const signed long long IMAX = 1e9 + 5;
const double PI = 3.141592653589793;
template <class T>
using max_pq = priority_queue<T>;
template <class T>
using min_pq = priority_queue<T, vector<T>, greater<T> >;
signed long long x, y;
template <class T>
T gcd(T a, T b) {
  if (a == 0) {
    x = 0, y = 1;
    return b;
  }
  T gc = gcd(b % a, a);
  T temp;
  temp = x;
  x = y - (b / a) * temp;
  y = temp;
  return gc;
}
signed long long po(signed long long a, signed long long x,
                    signed long long m) {
  if (x == 0) {
    return 1;
  }
  signed long long ans = 1;
  signed long long k = 1;
  while (k <= x) {
    if (x & k) {
      ans = ((ans * a) % m);
    }
    k <<= 1;
    a *= a;
    a %= m;
  }
  return ans;
}
signed long long modInverse(signed long long A, signed long long M) {
  gcd(A, M);
  return (x % M + M) % M;
}
int main() {
  signed long long n, i;
  cin >> n;
  vector<pair<signed long long, signed long long> > v(n - 1);
  vector<signed long long> cnt(n + 1);
  for (i = int(0); i <= int(n - 2); i++) {
    cin >> v[i].first >> v[i].second;
    cnt[v[i].first]++;
    cnt[v[i].second]++;
  }
  signed long long second = 0, e = n - 2;
  for (i = int(0); i <= int(n - 2); i++) {
    if (cnt[v[i].first] == 1 || cnt[v[i].second] == 1) {
      cout << second << "\n";
      ;
      second++;
    } else {
      cout << e << "\n";
      e--;
    }
  }
}
