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 $ values 200000 as bs xyc

values :: Int -> [Int] -> [Int] -> [Int] -> Int
values temp as bs [] = temp
values temp as bs (x:y:c:xs) = values ((temp<calc)?(temp,calc)) as bs xs where
 calc = ind x as + ind y bs - c

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