--なぁにがだめだったんでしょうか

import Data.List
import Data.Bool
import Data.Maybe

readInt :: String -> Int
readInt = read

main = do
    s <- map readInt.words<$>getContents
    putStr.unlines.map show $ solve s

solve :: [Int] -> [Int]
solve (a:b:q:s) = answers q
 where
  temples = take a s
  shrines = take b (drop a s)
  questions = drop (a+b) s
  answers 0 = []
  answers x = [faire x] ++ answers (x-1)
  faire x = if abs (qu x - te x) < abs (qu x - sh x)
   then abs (qu x - te x) + abs (te x - sh x) 
   else abs (qu x - sh x) + abs (te x - sh x)
  qu x = questions !! (x-1)
  te x = saikinchi (qu x) temples
  sh x = saikinchi (qu x) shrines

saikinchi x s = s !! (fromJust ix)
 where
  ix = elemIndex (minimum sanolist) sanolist
  sanolist = map (\a -> abs (a-x)) s