import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as C

readInt' = fst.fromJust.C.readInt
readLnInt = map readInt'.C.words<$>C.getLine
readCsInt n = concat<$>replicateM n readLnInt

x ? (a,b) = if x then a else b
a~>(f,x) = [a] ++ (null x)?([],f x)
half = flip div 2
aliq = ((0==).).mod

main = do
 [a,b,m] <- readLnInt
 as <- readLnInt
 bs <- readLnInt
 xyc <- readCsInt m
 print $ solve as bs xyc

solve as bs xyc = minn 20000 (values as bs xyc)

minn temp [] = temp
minn temp (a:x) = minn (minimum[temp,a]) x

values as bs [] = []
values as bs (x:y:c:xs) = [ind x as + ind y bs - c] ++ values as bs xs

ind number list = head $ drop (number - 1) list
