import Data.List
import Data.List.Split
import qualified Data.Vector as V
main = mapM_ (print . solve) . chunksOf 3 . map (map read . words) . lines =<< getContents
solve [[n,c],as,bs] = if as/=bs then -1 else dp V.! c V.! n where
  vas = V.fromList as
  dp = V.generate (c+1) $ \i->V.generate (n+1) $ \j->
    if i==0 then 1 else if j==0 then 0
    else (dp V.! i V.! (j-1) + dp V.! (i-1) V.! j * vas V.! (j-1))`mod`1000000007