Arrays Connection#12304

Arrays Connection

3 seconds
512 megabytes
Hard

You're given arrays consisting of positive integers.

The connection of two arrays and is the array with minimal size where is a prefix of and is a suffix of .

Calculate the expected size of the connection of two randomly picked arrays out of the arrays you're given.

The answer can be represented as a rational number \frac{p}{q}. Print p \cdot q^{-1} mod 10^9+7.

Input

The first line of the input contains an integer (1 \le t \le 2\cdot10^5) the number of testcases.

The description for the test cases follows.

The first line of each test case contains a single integer (1 \le n \le 2\cdot10^5) the number of arrays.

The following lines are of the form:

  • d_1 d_2 d_{sz} (1 \le d_i \le 2 \cdot 10^5)

It is guaranteed that the sum of sizes of all arrays over all test cases does not exceed 2\cdot10^5.

Output

For each test case output a single integer, the expected size modulo 10^9+7.

Examples

Example 1

Loading
Loading

Note

For the second test case:

The connection of a=\{6,7\} , b=\{6,7\} (array and array ) is c=\{6,7\} of size .

The connection of a=\{6,7\} , b=\{6,7,6,7\} (array and array ) is c=\{6,7,6,7\} of size .

The connection of a=\{6,7,6,7\} , b=\{6,7\} (array and array ) is c=\{6,7,6,7\} of size .

The connection of a=\{6,7,6,7\} , b=\{6,7,6,7\} (array and array ) is c=\{6,7,6,7\} of size .

So the expected size of the connection of two random arrays is \frac{2+4+4+4}{4} mod 10^9+7 which is equal to .

Scoring

Let be equal to the sum of sizes of all arrays over all test cases.

  • Subtask ( points): (m \le 500)

  • Subtask ( points): (m \le 5000)

  • Subtask ( points): all arrays have size

  • Subtask ( points): (m \le 50000)

  • Subtask ( points): all arrays have the same size

  • Subtask ( points): no additional constraints