cswork / OAOpen practice workspace

Wells FargoOA #7

Sum of Compressed Number for All Subarrays

Estimated HardJudge-ready

Topics (AI-labelled)DP BasicsBits & Math

For each contiguous subarray of the array, adjacent equal values compress into a single representative. The compressed number of that subarray is the number of different choices that produce the standard compressed array by keeping exactly one index in each maximal run of equal values and deleting the other indices of that run; if the subarray is already compressed, it is 0. Find the sum of the compressed numbers of all subarrays modulo 1,000,000,007.

Input

The first line contains t; then each test case gives n followed by n integers a[i]. Source constraints: 1≤t≤10, 1≤n≤100000, 1≤a[i]≤100000. This site additionally adds total n≤200000.

Output

For each test case, output one line with the answer modulo 1,000,000,007.

Example 1

Input:

1
5
6 7 3 6 6

Output:

8

Example 2

Input:

1
2
4 4

Output:

2

Example 3

Input:

1
4
3 3 3 3

Output:

16

Editorial

Loading solution…