P1591 Digit Count in Factorial

Description

Find how many times a certain digit appears in $n!$.

Input Format

The first line contains $t$ ($t \leq 10$), indicating the number of test cases. Each of the next $t$ lines contains a positive integer $n$ ($n \leq 1000$) and a digit $a$.

Output Format

For each test case, output a single integer, the number of times $a$ appears in $n!$.

Explanation/Hint

Translated by ChatGPT 5