← Home
package main

import (
	"bufio"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	readInt := func() int {
		c, err := in.ReadByte()
		for err == nil && c <= ' ' {
			c, err = in.ReadByte()
		}
		if err != nil {
			return 0
		}
		res := 0
		for c > ' ' {
			res = res*10 + int(c-'0')
			c, err = in.ReadByte()
		}
		return res
	}

	writeInt := func(n int64) {
		if n == 0 {
			out.WriteByte('0')
			out.WriteByte('\n')
			return
		}
		var buf [20]byte
		i := 19
		for n > 0 {
			buf[i] = byte('0' + n%10)
			n /= 10
			i--
		}
		out.Write(buf[i+1:])
		out.WriteByte('\n')
	}

	t := readInt()
	for ; t > 0; t-- {
		n := readInt()
		lMin := int(2e9)
		rMax := -1
		var minLCost int64 = 2e18
		var minRCost int64 = 2e18
		var minLRCost int64 = 2e18
		
		for i := 0; i < n; i++ {
			l := readInt()
			r := readInt()
			c := int64(readInt())
			
			if l < lMin {
				lMin = l
				minLCost = c
				minLRCost = 2e18
			} else if l == lMin {
				if c < minLCost {
					minLCost = c
				}
			}
			
			if r > rMax {
				rMax = r
				minRCost = c
				minLRCost = 2e18
			} else if r == rMax {
				if c < minRCost {
					minRCost = c
				}
			}
			
			if l == lMin && r == rMax {
				if c < minLRCost {
					minLRCost = c
				}
			}
			
			ans := minLCost + minRCost
			if minLRCost < ans {
				ans = minLRCost
			}
			writeInt(ans)
		}
	}
}