-- Try yukicoder -- author: Leonardone @ NEETSDKASU import Data.List (any, sort) main = putStrLn . unlines . solve . map read . tail . words =<< getContents solve x = map show . reverse $ foo [] x where foo a [] = a foo a (n1:n2:m:xs) = foo b zs where (ys, zs) = splitAt m xs ss = sort ys n = n1 + n2 (u, v) = foldl (\(uu, vv) w -> if uu > n then (uu, vv) else (uu + w, vv + 1)) (0, 0) ss ks = take v ss [mn, mx] = sort [n1, n2] (dk, di) = foldl (\(rk, ki) vk -> let xk = rk + vk in if xk <= mn then (xk, ki + 1) else (rk ,ki)) (0, 0) ks (h1, h2) = splitAt di ks ek = sum (0 : h2) r = case mn - dk of q | q == mn -> 0 0 -> if ek > mx then v - 1 else v _ -> if bar ks 0 then v else v - 1 where bar tts v1 = if v1 == mn then True else if v1 > mn then False else case tts of [] -> False t:ts -> (bar ts (v1 + t)) || (bar ts v1) b = r : a