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.

**Input:**

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.

**Output:**

For each test case, print in new line the sum as described in the problem. Print your answer modulo 10^9 + 7.

**Constraints:**

1 <= T <= 10^3

1 <= Length |String| <= 10^6

1 <= k <= 25, k<=Length |String|

**Example:**

**Input:**

2

010100010010 3

00100110 4

**Output:**

6

8

**Explanation:**

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.

Author: sajalagrawal

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.

GustavoMéndez | 191 |

VivSisMMM | 182 |

d_Coder00 | 177 |

ajayjadhav35 | 161 |

Astikeysingh | 154 |

Pulkit__Sharma__ | 694 |

Anirban166 | 652 |

abducodes | 562 |

Found_me | 542 |

Sathvik Avasarala | 514 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4559 |

Login to report an issue on this page.