#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 2e9;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline bool isPrime(long long x) {
  if (x <= 1) return 0;
  if (x <= 3) return 1;
  if (!(x % 2) || !(x % 3)) return 0;
  long long s = sqrt(1.0 * x) + EPS;
  for (long long i = 5; i <= s; i += 6) {
    if (!(x % i) || !(x % (i + 2))) return 0;
  }
  return 1;
}
inline long long fpow(long long n, long long k, long long p = 2e18) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
inline int inv(int a, long long p = 2e18) { return fpow(a, p - 2, p); }
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const int N = 3e5 + 5;
long long n, m;
long long a[N];
vector<int> adj[N];
void Solve() {
  cin >> n;
  vector<pair<int, int> > edges;
  map<pair<int, int>, int> mp;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    edges.push_back({u, v});
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (int((adj[i]).size()) == 1 && !mp.count({i, adj[i][0]})) {
      mp[{i, adj[i][0]}] = mp[{adj[i][0], i}] = cnt++;
    }
  }
  for (auto p : edges) {
    int u = p.first;
    int v = p.second;
    if (mp.count({u, v})) {
      cout << mp[{u, v}] << "\n";
    } else {
      cout << cnt++ << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int query = 1;
  int start = 1000 * clock() / CLOCKS_PER_SEC;
  while (query--) Solve();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC - start
       << "ms\n";
}
