```go
package main
import (
"bufio"
"os"
"sort"
"strconv"
)
var scanner *bufio.Scanner
var writer *bufio.Writer
func init() {
scanner = bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
scanner.Buffer(make([]byte, 2048*1024), 2048*1024)
writer = bufio.NewWriter(os.Stdout)
}
func nextInt() int {
scanner.Scan()
x, _ := strconv.Atoi(scanner.Text())
return x
}
func nextInt64() int64 {
scanner.Scan()
x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
return x
}
type Edge struct {
to int
a int64
b int64
}
func solve() {
n := nextInt()
adj := make([][]Edge, n+1)
// The problem states n-1 lines follow, for j from 2 to n.
for j := 2; j <= n; j++ {
p := nextInt()
a := nextInt64()
b := nextInt64()
adj[p] = append(adj[p], Edge{to: j, a: a, b: b})
}
ans := make([]int, n+1)
// DFS function
// u: current vertex
// currentA: sum of a_j from root to u
// pathB: slice containing sum of b_j from root to each ancestor (including root)
var dfs func(u int, currentA int64, pathB []int64)
dfs = func(u int, currentA int64, pathB []int64) {
for _, e := range adj[u] {
v := e.to
nextA := currentA + e.a
nextB := pathB[len(pathB)-1] + e.b
// Extend pathB for the child.
// Using append on the slice passed by value is safe in DFS because
// we complete the recursion for the child before the underlying array
// slot is reused by the next sibling. Preallocating capacity in initialPathB helps.
newPathB := append(pathB, nextB)
// We need to find the maximum prefix length (depth) L such that pathB[L] <= nextA.
// pathB is sorted strictly increasing.
// sort.Search returns the smallest index k such that the condition is true.
// We look for k such that pathB[k] > nextA.
idx := sort.Search(len(newPathB), func(k int) bool {
return newPathB[k] > nextA
})
// The index in pathB corresponds to the depth (length of prefix).
// If idx is the first element > nextA, then idx-1 is the last element <= nextA.
ans[v] = idx - 1
dfs(v, nextA, newPathB)
}
}
// pathB starts with root at depth 0, sum of b = 0
initialPathB := make([]int64, 0, n+1)
initialPathB = append(initialPathB, 0)
dfs(1, 0, initialPathB)
for i := 2; i <= n; i++ {
if i > 2 {
writer.WriteByte(' ')
}
writer.WriteString(strconv.Itoa(ans[i]))
}
writer.WriteByte('\n')
}
func main() {
defer writer.Flush()
t := nextInt()
for i := 0; i < t; i++ {
solve()
}
}
```