#include <bits/stdc++.h>
using namespace std;
bool Compare(int a, int b) { return a > b; }
priority_queue<int, vector<int>, std::function<bool(int, int)>> pq(Compare);
int binary_search(vector<int> &nums, int target, int lower, int upper) {
  if (lower > upper) {
    return -1;
  } else {
    int mid = (upper + lower) / 2;
    if (nums[mid] == target)
      return mid;
    else if (nums[mid] < target) {
      return binary_search(nums, target, mid + 1, upper);
    }
    return binary_search(nums, target, lower, mid - 1);
  }
}
int main() {
  int n, inp1, inp2;
  cin >> n;
  if (n == 2) {
    cout << 0 << '\n';
    return 0;
  } else if (n == 3) {
    cout << 0 << '\n' << 1 << '\n';
    return 0;
  }
  vector<vector<int>> adja(n + 1);
  vector<bool> leaf_vec(n + 1, true);
  vector<int> ans(n - 1, -1);
  map<pair<int, int>, int> inps;
  for (int i = 0; i < n - 1; i++) {
    cin >> inp1 >> inp2;
    adja[inp1].push_back(inp2);
    adja[inp2].push_back(inp1);
    if (adja[inp1].size() > 1) leaf_vec[inp1] = false;
    if (adja[inp2].size() > 1) leaf_vec[inp2] = false;
    inps[make_pair(inp1, inp2)] = i;
    inps[make_pair(inp2, inp1)] = i;
  }
  int leaf = 0;
  int leaf_pair = 0;
  for (int i = 1; i < leaf_vec.size(); i++) {
    if (leaf_vec[i]) {
      leaf = i;
      leaf_pair = adja[i][0];
      break;
    }
  }
  int counter = 0;
  ans[inps[make_pair(leaf, leaf_pair)]] = counter;
  counter += 1;
  queue<int> bfs;
  bfs.push(leaf);
  vector<bool> visited(n + 1, false);
  while (!bfs.empty()) {
    int top = bfs.front();
    bfs.pop();
    visited[top] = true;
    vector<int> new_nodes;
    for (auto &x : adja[top]) {
      if (!visited[x]) {
        new_nodes.push_back(x);
        visited[x] = true;
        bfs.push(x);
      }
    }
    if (new_nodes.size() > 1) {
      ans[inps[make_pair(top, new_nodes[0])]] = counter;
      counter += 1;
      ans[inps[make_pair(top, new_nodes[1])]] = counter;
      counter += 1;
      break;
    }
  }
  for (auto &x : ans) {
    if (x == -1) {
      x = counter;
      counter += 1;
    }
  }
  for (auto &x : ans) {
    cout << x << '\n';
  }
  return 0;
}
