import Control.Applicative
import Control.Monad
import Data.List
import Data.Vector.Unboxed (Vector, (!), (//))
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM

main :: IO ()
main = solve <$> f >>= mapM_ print
  where
    f = map (map read <$> words) <$> lines <$> getContents
    

solve :: [[Int]] -> [Int]
solve xs = map (\[i, j] -> cnt ! (toIdx (i, j)) `div` (product [1..(10-i)])) xs
  where
    toIdx (i, j) = i * 331 + j
    cnt :: Vector Int
    cnt = V.create $ do
      v <- VM.replicate (11 * 331) 0
      forM_ (permutations [0..9]) $ \ps -> do
        forM_ (zip [1..10] (scanl1 (+) (zipWith (*) [1..10] ps))) $ \(i, j) -> do
          VM.modify v (+1) (toIdx (i, j))
      return v

