Associated Course(s):
Sudo Placement 2019

In mathematics, a **subsequence** is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

For example **abc** is a subsequence of **azbxc** but **axb** is not a subsequence of **azbxc**.

You will be given strings consisting of lower case English alphabets. The task for each string is to print the number of distinct subsequences (include empty subsequence).

**Input: **

The first line of input contains a single integer **T** denoting the number of test cases.

Then **T** test cases follow. The first and only line of each test case consists of a string of lower case English alphabets.

**Output:**

Corresponding to each test case, in a new line, print the number distinct subsequences. The answer may be too large, so print the answer modulo 10^{9}+7.

**Constraints:**

1 ≤ **T** ≤ 100

1 ≤ **length of string** ≤ 1000

**Example:**

**Input**

2

aa

abbb

**Output**

3

8

**Explanation**:

In first test case for aa, the set of distinct substrings will {a, aa, Ø}. Here Ø means the empty substring.

In second test case for abbb the set is {a, ab, abb, abbb, b, bb, bbb, Ø}.

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.

thanuvinu94 | 238 |

the_coder95 | 215 |

ShivayLamba | 208 |

sandeep.prajapati | 129 |

Ashish Kumar Vaishy | 114 |

the_coder95 | 1441 |

RishabhTanwar1 | 1110 |

thanuvinu94 | 914 |

tathagat289 | 668 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4897 |

Quandray | 4547 |

Login to report an issue on this page.