#P7801. Equal Sentences

Equal Sentences

Equal Sentences

Problem Description

Sometimes, changing the order of the words in a sentence doesn't influence understanding. For example, if we change "what time is it", into "what time it is"; or change "orz zhang three ak world final", into "zhang orz three world ak final", the meaning of the whole sentence doesn't change a lot, and most people can also understand the changed sentences well. Formally, we define a sentence as a sequence of words. Two sentences SS and TT are almost-equal if the two conditions holds:

  1. The multiset of the words in SS is the same as the multiset of the words in TT.
  2. For a word α\alpha, its ithi^\mathrm{th} occurrence in SS and its ithi^\mathrm{th} occurrence in TT have indexes differing no more than 11. (The kthk^\mathrm{th} word in the sentence has index kk.) This holds for all α\alpha and ii, as long as the word α\alpha appears at least ii times in both sentences. Please notice that "almost-equal" is not a equivalence relation, unlike its name. That is, if sentences AA and BB are almost-equal, BB and CC are almost-equal, it is possible that AA and CC are not almost-equal. Zhang3 has a sentence SS consisting of nn words. She wants to know how many different sentences there are, which are almost-equal to SS, including SS itself. Two sentences are considered different, if and only if there is a number ii such that the ithi^\mathrm{th} word in the two sentences are different. As the answer can be very large, please help her calculate the answer modulo 109+710^9 + 7.

Input

The first line of the input gives the number of test cases, T  (1T100)T \; (1 \le T \le 100). TT test cases follow. For each test case, the first line contains an integer n  (1n105)n \; (1 \le n \le 10^5), the number of words in the sentence. The second line contains the sentence SS consisting of nn words separated by spaces. Each word consists of no more than 1010 lowercase English letters. The sum of nn in all test cases doesn't exceed 2×1052 \times 10^5.

Output

For each test case, print a line with an integer, representing the answer, modulo 109+710^9 + 7.

Sample Input

2
6
he he zhou is watching you
13
yi yi si wu yi si yi jiu yi jiu ba yao ling

Sample Output

8
233

Source

2020 Multi-University Training Contest 4