import Control.Monad (replicateM_) import Data.List (foldl1') q = 10^9 + 7 :: Int fac 0 = 1 fac n = foldl1' (\x y -> x * y `mod` q) [1..n] modInv a = let (x, _) = extGCD a q in x `mod` q where extGCD a 0 = (1, 0) extGCD a b = let (x, y) = extGCD b $ a `mod` b in (y, x - (a `div` b) * y) c n k | n < k = 0 | otherwise = fac n * modInv (fac k * fac (n - k)) `mod` q p n k | n < k = 0 | otherwise = fac n * modInv (fac (n - k)) `mod` q h 1 k = 1 h n k = fac (n + k - 1) * modInv (fac k * fac (n - 1)) `mod` q f x = do let (a:ns) = init $ map g x (n:k:_) = map read $ words ns case a of 'C' -> c n k 'P' -> p n k 'H' -> h n k where g '(' = ' ' g ',' = ' ' g x = x main = do t <- read <$> getLine replicateM_ t $ print . f =<< getLine