#include <bits/stdc++.h>
using namespace std;
void READ(vector<long long> &v, long long n) {
  long long a;
  for (long long i = 0; i < n; i = i + 1) {
    cin >> a;
    v.push_back(a);
  }
}
void PRINT(vector<long long> &v, long long a = 0) {
  for (long long i = a; i < v.size(); i = i + 1) {
    cout << v[i] << " ";
  }
  cout << "\n";
}
double logy(long long n, long long b) {
  if (b == 0) {
    return (-1);
  }
  if (n == 1) {
    return (0);
  }
  return ((double)log10(n) / log10(b));
}
long long power(long long k, long long n, long long m = 1000000007) {
  long long res = 1;
  while (n) {
    if (n % 2 != 0) {
      res = (res * k) % m;
    }
    k = (k * k) % m;
    n = n / 2;
  }
  return (res);
}
long long n, m, k;
bool ok = false;
vector<vector<long long> > v;
set<long long> s;
map<pair<long long, long long>, long long> mp;
void dfs(long long i, long long par, long long ed) {
  for (auto j : v[i]) {
    if (j != par) {
      ed = *s.lower_bound((ed + 2 + n - 1) % (n - 1));
      s.erase(ed);
      mp[make_pair(i, j)] = ed;
      dfs(j, i, ed);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  std::cout.unsetf(std::ios::floatfield);
  std::cout.precision((long long)10);
  long long a, b, c, d, i, j, t, x, y, z;
  long long p, q, r, u, w;
  char ch, chr;
  string str, st, str1, str2, str3, str4;
  cin >> n;
  v.resize(n + 1);
  vector<pair<long long, long long> > edge;
  for (i = 0; i < n - 1; i++) {
    cin >> a >> b;
    edge.push_back(make_pair(a, b));
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (i = 0; i < n - 1; i++) {
    s.insert(i);
  }
  dfs(1, -1, -2);
  for (i = 0; i < n - 1; i++) {
    cout << mp[edge[i]] << "\n";
  }
}
