Given a string S, consisting only of ‘0’ and ‘1’, and also you are given an integer k. You are asked to find the sum of all unique substrings (in decimal notation) of length k in the string, such that string S is the repetition of these substrings. If the string S can’t be split into substrings of length k without leaving any characters in the string, print -1.
The first line consists of a single integer T denoting the number of test cases. Next T lines follow each of which consists of string S and an integer k.
For each test case, print in new line the sum as described in the problem. Print your answer modulo 10^9 + 7.
1 <= T <= 10^3
1 <= Length |String| <= 10^6
1 <= k <= 25, k<=Length |String|
Case 1: Unique substrings are “010” and “100”. The required sum is 2+4=6.
Case 2: Unique substrings are "0010" and "0110". Hence, the sum = 2 + 6 = 8.
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.