'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  const n = getInt()
  const inc = new Array(n + 1).fill(0)
  const G = []
  const ans = {}
  const out = []
  for (let i = 1; i < n; ++i) {
    const ab = getInts()
    const a = ab[0]
    const b = ab[1]
    out.push(make_pair(a, b))

    inc[a] ++
    inc[b] ++
    if (!G[a]) G[a] = []
    if (!G[b]) G[b] = []

    G[a].push(b)
    G[b].push(a)
    ans[make_pair(a, b)] = -1
  }

  let node = -1
  let mx = 0
  for (let i = 1; i <= n; ++i) {
    if (inc[i] > mx) {
      mx = inc[i]
      node = i
    }
  }

  let cnt = 0
  for (let i = 0; i < G[node].length; ++i) {
    const other = G[node][i]
    ans[make_pair(node, other)] = cnt ++
  }

  for (let i in ans) {
    if (ans[i] === -1) ans[i] = cnt ++
  }
  
  for (let i in out) {
    print(ans[out[i]])
  }
}

function make_pair (a, b) {
  const arr = [a, b]
  arr.sort()
  return arr[0] + '-' + arr[1]
}
