import Control.Arrow
import Data.Char
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B
import qualified Data.IntSet as IS
main=mapM_ print.solve.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve(a:b:q:stxs)=map f xs where
  (ss,(ts,xs))=(IS.fromList***first IS.fromList.splitAt b).splitAt a$stxs
  f x=minimum[g x ts ss,g x ss ts]
g x as bs=minimum.map(minimum.map fst.h as)$h bs(0,x)
h as(d,x)=map(\y->(d+abs(x-y),y))$mapMaybe(\f->f x as)[IS.lookupLE,IS.lookupGE]