Count number of substrings
Submissions: 3150   Accuracy:

36.9%

  Difficulty: Easy   Marks: 2

Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.

Input:

The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of a string S.
The second line of each test case contains integer K.

Output:

Corresponding to each test case, in a new line, print the count all possible substrings that has exactly k distinct characters.

Constraints:

1 ≤ T ≤ 100
1 ≤ string length ≤ 1000
1 ≤ K ≤ 26

Example:

Input
1
aba
2

Output
3

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

Author: rajatjha


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.