#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
const long long mod = 1e9 + 7;
bool is(long long n) { return (ceil(log2(n)) == floor(log2(n))); }
bool q(const pair<long long, long long> &a,
       const pair<long long, long long> &b) {
  if (a.second == b.second) return a.first < b.first;
  return a.second < b.second;
}
bool q2(const pair<long long, long long> &a,
        const pair<long long, long long> &b) {
  if (a.first == b.first) return a.second > b.second;
  return a.first > b.first;
}
vector<long long> g[100005];
bool vis[100005];
map<pair<long long, long long>, long long> m;
long long ans = 0, ans2;
long long p, n, cc = 1;
void dfs(long long root) {
  vis[root] = true;
  queue<long long> q;
  q.push(root);
  while (!q.empty()) {
    root = q.front();
    q.pop();
    for (auto i : g[root]) {
      if (vis[i]) continue;
      m[{root, i}] = ans;
      m[{i, root}] = ans;
      ans++;
      vis[i] = true;
      q.push(i);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) {
    ans = 0;
    cc = 1;
    memset(vis, 0, sizeof(vis));
    long long u, v;
    cin >> n;
    ans2 = n - 2;
    vector<pair<long long, long long>> vp;
    for (long long i = 0; i < n - 1; i++) {
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
      vp.push_back({u, v});
    }
    dfs(1);
    for (auto i : vp) {
      cout << m[{i.first, i.second}] << endl;
    }
  }
  return 0;
}
