#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
  int res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
template <class T>
void chmax(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void chmin(T& a, const T& b) {
  a = min(a, b);
}
vector<vector<pair<int, int>>> adj;
vector<int> val;
vector<bool> visited;
int mini = 0;
bool dfs(int v) {
  visited[v] = true;
  int flag = 0;
  for (auto u : adj[v]) {
    if (!visited[u.second]) {
      if (dfs(u.second)) val[u.first] = mini++;
      flag = 1;
    }
  }
  if (!flag) {
    return true;
  } else
    return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, t, a;
  cin >> n;
  adj = vector<vector<pair<int, int>>>(n + 1);
  val = vector<int>(n - 1, -1);
  visited = vector<bool>(n + 1, false);
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> t;
    adj[a].push_back({i, t});
    adj[t].push_back({i, a});
  }
  dfs(1);
  for (int i = 0; i < n - 1; i++) {
    if (val[i] == -1) val[i] = mini++;
  }
  for (int i = 0; i < n - 1; i++) cout << val[i] << endl;
  return 0;
}
