import Data.List (sort)
import Data.Array ((!), listArray, Array)

readArr :: IO [Int]
readArr = (map (\s -> read s :: Int)) <$> (words <$> getLine)

pref :: Int -> [Int] -> [Int]
pref _ [] = []
pref s (x: xs) = (s + x: pref (s + x) xs)

findH :: Array Int Int -> Int -> Int -> Int -> Int
findH arr a l r = if l + 1 == r
  then r
  else let m = (l + r) `div` 2 in if arr ! m < a then findH arr a m r else findH arr a l m

find :: Array Int Int -> Int -> Int -> Int
find arr a n = let ans = findH arr a (-1) n in if ans == n then -1 else ans + 1

que :: Array Int Int -> Int -> Int-> IO ()
que _ _ 0 = pure ()
que arr n i = do
  a <- readLn :: IO Int
  print $ find arr a n
  que arr n (i - 1)

for :: Int -> IO ()
for 0 = pure ()
for i = do
  (n: q: _) <- readArr
  arr <- readArr
  que (listArray (0, n) (pref 0 (reverse $ (3000000000: sort arr)))) n q
  for $ i - 1

main :: IO ()
main = do
  t <- readLn :: IO Int
  for t

import Data.List (sortBy, findIndex)
import Data.Array
import Control.Monad (replicateM_, replicateM)

main :: IO ()
main = read <$> getLine >>= flip replicateM_ singleCase

singleCase :: IO ()
singleCase = map read . words <$> getLine >>=
             \([n, q]) -> map read . words <$> getLine >>=
             \as -> let pc = precompute n as in
                      replicateM_ q (read <$> getLine >>= print . ansQuery pc)

ansQuery :: Array Int Int -> Int -> Int
ansQuery xs n = case binSearch xs n of
                  Just i -> i
                  Nothing -> -1

invOrd :: (Ord a) => a -> a -> Ordering
invOrd x y = case compare x y of
               EQ -> EQ
               LT -> GT
               GT -> LT

precompute :: Int -> [Int] -> Array Int Int
precompute n as = let (s:ss) = sortBy invOrd as in
                    listArray (1, n) $ scanl (+) s ss

binSearch :: Array Int Int -> Int -> Maybe Int
binSearch a e = uncurry (binSearch' a e) (bounds a)

binSearch' :: Array Int Int -> Int -> Int -> Int -> Maybe Int
binSearch' a e i j | (e <= (a!i)) = Just i
                   | (e > (a!j))  = Nothing
                   | (j <= i+1)   = Just j
                   | otherwise = let middle = div (i+j) 2 in
                                   case compare e (a!middle) of
                                     EQ -> Just middle
                                     GT -> binSearch' a e (1+middle) j
                                     LT -> binSearch' a e i middle


import Data.List

solvem []     last acc = acc
solvem (x:xs) last acc = solvem xs last' acc'
  where (last', acc') = if abs (x - last) <= 1 then (last, acc) else (x+1, acc+1)

solveM []     last acc = acc
solveM (x:xs) last acc = solveM xs last' acc'
  where (last', acc') = if last+1 > x+1 then (last, acc) else (nxt, acc+1)
        nxt = max (last+1) (x-1)

main :: IO ()
main = do
  getLine
  xs <- sort . map read . words <$> getLine
  putStrLn $ show (solvem xs 1000000 0) ++ " " ++ show (solveM xs (-1000000) 0)

{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Data.List
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

countMoves :: [Int] -> (Int, Int)
countMoves xs = let (mn, mx) = foldl' (\(mn, mx) x -> (min' mn x, max' mx x)) (mempty, mempty) xs
                in (IntSet.size mn, IntSet.size mx)
  where
    min' m x | any (`IntSet.member` m) [x - 1, x, x + 1] = m -- Move to occupied house, if possible
             | otherwise = IntSet.insert (x + 1) m
    max' m x | Just x' <- find (`IntSet.notMember` m) [x - 1, x, x + 1] = IntSet.insert x' m  -- Move to unoccupied house
             | otherwise = m  -- Must move to occupied house

main = do
    n :: Int <- fmap read getLine
    xs <- fmap (sort . fmap read . words) getLine
    let (mn, mx) = countMoves xs
    putStr (show mn)
    putChar ' '
    putStrLn (show mx)

{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Data.List
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

countMoves :: [Int] -> (Int, Int)
countMoves xs = let (mn, mx) = foldl' (\(mn, mx) x -> (min' mn x, max' mx x)) (mempty, mempty) xs
                in (IntSet.size mn, IntSet.size mx)
  where
    min' m x | any (`IntSet.member` m) [x - 1, x, x + 1] = m -- Move to occupied house, if possible
             | otherwise = IntSet.insert x m
    max' m x | Just x' <- find (`IntSet.notMember` m) [x - 1, x, x + 1] = IntSet.insert x' m  -- Move to unoccupied house
             | otherwise = m  -- Must move to occupied house

main = do
    n :: Int <- fmap read getLine
    xs <- fmap (sort . fmap read . words) getLine
    let (mn, mx) = countMoves xs
    putStr (show mn)
    putChar ' '
    putStrLn (show mx)

{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Data.List
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

countMoves :: [Int] -> (Int, Int)
countMoves xs = let (mn, mx) = foldl' (\(mn, mx) x -> (min' mn x, max' mx x)) (mempty, mempty) xs
                in (length mn, length mx)
  where
    min' m x | any (`elem` m) [x - 1, x, x + 1] = m -- Move to occupied house, if possible
             | otherwise = insert x m
    max' m x | Just x' <- find (`notElem` m) [x - 1, x, x + 1] = insert x' m  -- Move to unoccupied house
             | otherwise = m

main = do
    n :: Int <- fmap read getLine
    xs <- fmap (fmap read . words) getLine
    let (mn, mx) = countMoves xs
    putStr (show mn)
    putChar ' '
    putStrLn (show mx)