#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
inline void swp(long long int &a, long long int &b) {
  auto temp = a;
  a = b;
  b = temp;
}
const long long int N = 10;
vector<long long int> tree[N];
map<pair<long long int, long long int>, long long int> m;
vector<long long int> ans(N);
long long int leaf1 = -1, leaf2 = -1;
vector<long long int> path;
void dfs(long long int s, long long int p = -1) {
  if ((long long int)tree[s].size() == 1 && p != -1) {
    if (leaf1 == -1)
      leaf1 = s;
    else if (leaf2 == -1)
      leaf2 = s;
    else
      return;
  }
  for (auto ch : tree[s]) {
    if (ch != p) {
      dfs(ch, s);
    }
  }
}
long long int dfs2(long long int s, long long int d, long long int p,
                   long long int &cntr) {
  if (s == d) {
    path.push_back(s);
    return 1;
  }
  for (auto ch : tree[s]) {
    if (ch != p) {
      long long int ret = dfs2(ch, d, s, cntr);
      if (ret != -1) {
        path.push_back(s);
        return 1;
      }
    }
  }
  return -1;
}
void solve() {
  long long int n;
  cin >> n;
  ans.assign(N, -1);
  for (long long int i = 0; i < n - 1; ++i) {
    long long int x, y;
    cin >> x >> y;
    x--, y--;
    tree[x].push_back(y);
    tree[y].push_back(x);
    m[{x, y}] = i;
    m[{y, x}] = i;
  }
  if (n == 2) {
    cout << 0 << "\n";
    return;
  }
  dfs(0);
  if (leaf2 == -1) {
    leaf2 = 0;
  }
  long long int cnt = 3;
  dfs2(leaf1, leaf2, -1, cnt);
  long long int edge1 = m[{path[0], path[1]}];
  ans[edge1] = 1;
  long long int edge2 = m[{path[(long long int)path.size() - 2],
                           path[(long long int)path.size() - 1]}];
  ans[edge2] = 2;
  for (long long int i = (long long int)path.size() - 2; i >= 2; --i) {
    long long int edge = m[{path[i], path[i - 1]}];
    ans[edge] = cnt++;
  }
  for (long long int i = 0; i < n - 1; ++i) {
    if (ans[i] == -1) {
      if (cnt == n - 1)
        cout << 0 << "\n";
      else
        cout << cnt++ << "\n";
    } else
      cout << ans[i] << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  for (auto x = 0; x < t; x++) {
    solve();
  }
  return 0;
}
