#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const int eps = 1e-6;
const int N = 2e5 + 5;
vector<int> v[N];
int dis[N], dis1[N];
int max_d;
int far, far1;
map<pair<int, int>, int> mp;
vector<pair<int, int> > edge;
void dfs(int s, int p, int d, int t) {
  if (t == 0)
    dis[s] = d;
  else
    dis1[s] = d;
  if (max_d < d) {
    max_d = d;
    if (t == 0)
      far = s;
    else
      far1 = s;
  }
  for (auto x : v[s]) {
    if (x == p) continue;
    dfs(x, s, d + 1, t);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0, x, y; i < n - 1; i++) {
    cin >> x >> y;
    --x, --y;
    v[x].push_back(y);
    v[y].push_back(x);
    edge.push_back({x, y});
  }
  dfs(0, -1, 0, 0);
  max_d = 0;
  dfs(far, -1, 0, 1);
  int half = (max_d + 1) / 2;
  memset(dis, 0, sizeof(dis));
  dfs(far1, -1, 0, 0);
  int center = -1;
  for (int i = 0; i < n; i++) {
    if (dis[i] == half && dis1[i] == max_d - half) {
      center = i;
      break;
    }
  }
  queue<int> q;
  q.push(center);
  vector<int> vis(n, 0);
  vis[center] = 1;
  int l = 0, r = n - 2;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = 0; i < int(v[cur].size()); i++) {
      if (vis[v[cur][i]]) continue;
      vis[v[cur][i]] = 1;
      if (i % 2 == 0)
        mp[{cur, v[cur][i]}] = l++;
      else
        mp[{cur, v[cur][i]}] = r--;
      q.push(v[cur][i]);
    }
  }
  for (auto x : edge) {
    if (mp.find({x.first, x.second}) != mp.end()) {
      cout << mp[{x.first, x.second}] << '\n';
    } else {
      cout << mp[{x.first, x.second}] << '\n';
    }
  }
  return 0;
}
