import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Data.Ord

main :: IO ()
main = breads >>= main'
    where
        main' (n : _) = replicateM n (edit <$> breads) >>= print . solve
        edit [s, t, c] = (s, t, c)

solve :: [(Int, Int, Int)] -> Int 
solve = fst . foldl' ff (0, 0) . groupBy gf2 . sortBy (comparing fst) . concatMap mf . groupBy gf . sortBy sf
    where
        sf (ls, lt, lc) (rs, rt, rc) = compare lc rc `mappend` compare ls rc `mappend` compare lt rt
        gf (_, _, lhs) (_, _, rhs) = lhs == rhs
        gf2 (lt, _) (rt, _) = lt == rt
        mf (x@(xs, xt, c) : y@(ys, yt, _) : zs)
            | xt == ys = mf $ (xs, yt, c) :zs
            | otherwise = (2 * xs, 1) : (2 * xt, -1) : mf (y : zs)
        mf ((xs, xt, _) : _) = (2 * xs - 1, 1) : (2 * xt, -1) : []
        mf _ = []
        ff (acc, current) xs = (max acc next, next)
            where
                next = v + current
                v = foldl' (\acc (_, n) -> acc + n) 0 xs


breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)