eolymp
bolt
Try our new interface for solving problems
Problems

The Idiot of the Year Contest!

The Idiot of the Year Contest!

There is just one basic rule in the Idiot of the Year Contest (IYC)! The contestant picks a random digit between \textbf{0} and \textbf{9}, computes the factorial of the day of the year he/she is born, and counts the how many times the digit picked appears in the factorial. The contestant with highest count is the Idiot of the Year! For example, if you are born on \textbf{5}^thof Mordad which is the \textbf{129}^th day of the year, and you pick the digit \textbf{6}, your score will be the number of times the digit \textbf{6}appears in \textbf{129!} (that is \textbf{1}×\textbf{2}×\textbf{3}×...×\textbf{129}). The chief judge of IYC wants you to write a program to get an integer which is the day of the year a contestant is born on and a digit and report the number of times the digit appears in the factorial of the first number. \InputFile The first line of the input contains a single integer \textbf{t} which is the number of test cases, followed by \textbf{t} lines each containing the data for a test case having two numbers. The first number is the day of the year a contestant is born and the second one is the digit he/she has picked. \OutputFile The output contains \textbf{t} lines, each having one integer which is the number of times the digit appears in the factorial of the first number.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2
5 2
7 0
Output example #1
1
2