{-# LANGUAGE MultiWayIf #-}
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.Array

main :: IO ()
main = do
  [n, c] <- map read . words <$> getLine
  a <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
  b <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
  let
    po = array ((0, 0), (400, c)) [((i, j), if i == 0 then 0 else ((po ! (i-1, j)) + i^j) `mod` 1000000007) | i <- [0..400], j <- [0..c]]
    ans = array ((0, 0), (n, c)) $ do
      i <- [0..n]
      j <- [0..c]
      return $ (,) (i, j) $ if
        | i == 1 && j == 0 -> (b !! (i-1)) - (a !! (i-1)) + 1
        | j == 0 -> 1
        | i == 0 -> 0
        | otherwise -> sum [((ans ! (i-1, j-k)) * ((po ! (b !! (i-1), k)) - (po ! ((a !! (i-1)) - 1, k)))) `mod` 1000000007 | k <- [0..j]]
  print $ ans ! (n, c) `mod` 1000000007
