#P1787I. Treasure Hunt
Treasure Hunt
Description
Define the beauty value of a sequence as the maximum value of , where , , are all integers and or . Note that when or , when .
For example, when , we may have , , so the beauty value is . And when , we have so the beauty value is .
You are given a sequence of length , determine the sum of the beauty value of all non-empty subsegments () of the sequence .
Print the answer modulo .
Each test contains multiple test cases. The first line contains an integer () — the number of test cases.
The first line contains an integer () — the length of .
The second line contains integers () — the given sequence.
It's guaranteed that the sum of does not exceed .
For each test case, print a line containing a single integer — the answer modulo .
Input
Each test contains multiple test cases. The first line contains an integer () — the number of test cases.
The first line contains an integer () — the length of .
The second line contains integers () — the given sequence.
It's guaranteed that the sum of does not exceed .
Output
For each test case, print a line containing a single integer — the answer modulo .
Note
In the second test case, for the subsequence , when , , , .
In the third test case, there is only one non-empty consecutive subsequence . When , , , .