Number of subsequences in a string divisible by n
Submissions: 978   Accuracy:

23.6%

  Difficulty: Easy   Marks: 2

Given a string consisting of digits 0-9, count the number of subsequences in it divisible by n.

 

Input:

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer M and N where M denotes the length of the numeric string.

The second line of each test case contains the numeric string.


Output:

Output the number of subsequences dicisible by N. Since the number can be quite large print the answer modulo 109+7.


Constraints:

1<= T <=100

1<= M <=1000

1<= N <=1000


Example:

Input:

2

4 4

1234

3 6

330

Output:

4

4

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Sujnesh Mishra
Author: sujnesh


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.